将另一个查询结果中的列添加到临时表

时间:2013-03-15 09:23:51

标签: sql sql-server

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

0 个答案:

没有答案