我实现了一些代码:
BEGIN
DECLARE
@SQL AS NVARCHAR(MAX),
@TempTable AS NVARCHAR(MAX)
SET @SQL = 'SELECT * from Employee where Instance_ID = 1';
BEGIN
CREATE TABLE ##tempResults (SQL NVARCHAR(4000))
INSERT INTO ##tempResults EXEC @SQL;
SET @TempTable= 'select * from #tempResults ORDER BY CASE WHEN ' + @index+ ' =1 THEN [First Name] END DESC '+ ',' + ' CASE WHEN ' + @index + '=2 THEN [Last name] END DESC'
END
EXEC sp_executesql @TempTable;
END
我想将动态结果插入临时表但我无法执行语句并获取错误。请告诉我我应该怎么做?
显示错误:
“消息203不是有效的标识符。”