-1

我有这个表结构:

Product1 , product2, product3....., productn

与同一列:

Item, desc, price  

我想合并所有这些表:product1 直到 productn,比如

select item,desc,price
from (select name from sys.tables)

或者

select item,desc, price
from (uninon product1 to product n)

通过参数化。

4

1 回答 1

1

一种解决方案可能是将自定义字符串与 select 连接起来。您可以按名称过滤以获取您不会显示的表格。例如..

declare @qry varchar(max)
declare @name varchar(200)
Declare Cursor1 Cursor 
   for
   SELECT name FROM dbo.tables
Open Cursor1
fetch Cursor1 into @name
while @@fetch_status = 0
begin
    -- here concat your query with @name in @qry
fetch Cursor1 into @name
end
Close Cursor1
Deallocate Cursor1

exec @qry
于 2013-09-20T20:45:21.133 回答