22,210
社区成员
发帖
与我相关
我的任务
分享
declare @xuhao int
declare @count int
declare @table varchar(50)
declare @date datetime
declare @sql varchar(8000)
set @sql = ''
set @date = '2008-3-1'
select identity(int,1,1) as orders,序号,表名 into #temp from tb where 时间 = @date order by 序号 desc
select @count = count(1) from #temp
while @count > 0
begin
select @xuhao = 序号,@table = 表名 from #temp where orders = @count
set @sql = @sql+' union all select 序号,时间,地点,主题,字段1,字段2
from tb,(select top 1 字段1,字段2 from '+@table+')a where 序号 = ' + cast(@xuhao as varchar(10))
set @count = @count - 1
end
drop table #temp
set @sql = substring(@sql,12,8000)
print @sql
exec( @sql)
declare @xuhao int
declare @count int
declare @table varchar(50)
declare @date datetime
declare @sql varchar(8000)
set @sql = ''
set @date = '2008-3-1'
select identity(int,1,1) as orders,序号,表名 into #temp from tb where 时间 = @date order by 序号 desc
select @count = count(1) from #temp
while @count > 0
begin
select @xuhao = 序号,@table = 表名 from #temp where orders = @count
set @sql = @sql+' union all select 序号,时间,地点,主题,字段1,字段2
from tb,(select top 1 区域 from '+@table+')a where 序号 = ' + cast(@xuhao as varchar(10))
set @count = @count - 1
end
drop table #temp
set @sql = substring(@sql,12,8000)
print @sql
exec( @sql)