我有一个包含动态生成表的数据库。我正在编写一个存储过程来对生成的表执行查询,我需要在查询分析器工具(或类似工具)中查看结果。
我目前拥有的是:
DECLARE @TableName sysname
DECLARE TableNameCursor CURSOR FOR
SELECT TableName FROM [xxxTables] WHERE xxx...
OPEN TableNameCursor
FETCH NEXT FROM TableNameCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @Query nvarchar
SET @Query = 'SELECT * FROM ' + @TableName
EXEC sp_executesql @Query
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM TableNameCursor INTO @TableName
END
但由于我有多个选择,我没有得到输出。如何修复存储过程以显示结果?
所有的桌子都有相同的布局,所以我可以加入它们。