2

I´m trying to get my result into a temp table but can´t get it to work.

DECLARE @query nvarchar(max)
SET @query = N'SELECT * INTO ##TmpTbl FROM (SELECT * FROM Tbl1)'
EXEC(@query)

What am i doing wrong?

NOTE: I can NOT pre define temp table/table variable because of the actual question being run is a pivot question without pre defined columns in it´s result.

4

1 に答える 1

4

サブクエリにエイリアスがありません:

DECLARE @query nvarchar(max)
SET @query = N'SELECT * 
               INTO ##TmpTbl 
               FROM (SELECT * FROM Tbl1) src'  <--- you need an alias
EXEC(@query)
于 2012-11-01T15:25:13.663 に答える