Insert Data Into Temp Table with Query

后端 未结 8 1972
春和景丽
春和景丽 2020-12-12 12:43

I have an existing query that outputs current data, and I would like to insert it into a Temp table, but am having some issues doing so. Would anybody have some insight on h

8条回答
  •  孤城傲影
    2020-12-12 13:20

    SQL Server R2 2008 needs the AS clause as follows:

    SELECT * 
    INTO #temp
    FROM (
        SELECT col1, col2
        FROM table1
    ) AS x
    

    The query failed without the AS x at the end.


    EDIT

    It's also needed when using SS2016, had to add as t to the end.

     Select * into #result from (SELECT * FROM  #temp where [id] = @id) as t //<-- as t
    

提交回复
热议问题