我试图将动态表名加载到本地表中。从我发现的示例中看起来很简单,但是我收到了错误消息。 - > '#outtbl_15133897'
附近的语法不正确希望另一组眼睛可以看到我失踪的东西。感谢
DECLARE @OutTbl TABLE ( Name varchar(100), type varchar(20), row int );
DECLARE @curName as NVARCHAR(MAX);
DECLARE @sqlCommand as NVARCHAR(MAX);
SET @curName = '#outtbl_' + LEFT(replace(replace(CONVERT (time, GETDATE()),':',''),'.',''),8);
SET @sqlCommand = 'CREATE TABLE #OutTbl ( Name varchar(100), type varchar(20), row int ); '
+ 'INSERT INTO #outtbl SELECT c.Name,c.Type, ROW_NUMBER() OVER(ORDER BY c.QueryID,c.GroupID,c.ColumnID) as row '
+ 'FROM MYDB.dbo.DynamicReport_Columns c '
+ 'INNER JOIN MYDB.dbo.DynamicReport_Tables t on t.TableID = c.TableID '
+ 'WHERE c.QueryID=1 and c.GroupID=1 and IsOutput <> ''N'';';
SET @curName = @curName + ' TABLE OUTPUT';
EXEC sys.sp_executesql @sqlCommand,@curName,@OutTbl output
答案 0 :(得分:-1)
我不是百分之百......我认为我有类似的问题,但我通过将临时表设为全局临时表来解决它... ## outtbl