我有一个查询,它创建一个临时表#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