0

我有一个查询,它创建一个#object带有一列的临时表(id int),我想#object用另一个查询结果中的列进行扩展。我试过使用游标:

CREATE TABLE #object(ID int)

DECLARE @q int    
DECLARE @getid CURSOR

SET @getid= CURSOR FOR
select Q.Question /*, QR.ResponseText, QR.DynamicQuestionResponseID*/  from     DynamicForms_Question as Q
inner join DynamicForms_QuestionResponse as QR on Q.DynamicQuestionID = QR.DynamicQuestionID 
where Q.ModuleID = 729 
and QR.ResponseDateTime = '2012-12-27 11:31:00'
and QuestionType <> 'Label'
and QuestionType <> 'HR'
order by Q.SortOrder asc

OPEN @getid
FETCH NEXT
FROM @getid INTO @q
WHILE @@FETCH_STATUS = 0
BEGIN
Alter Table #object add -- what can i use here????
FETCH NEXT
FROM @getid INTO @q
END

CLOSE @getid
DEALLOCATE @getid

drop table #object
4

0 回答 0