declare @db varchar(50),@tb varchar(50),@cnt int,@sql nvarchar(4000)
,@tableName varchar(100) ,@tableName1 varchar(100),@tableName2 varchar(100),@tb1 varchar(50),@tb2 varchar(50)
set @cnt=0
set @tableName='Item'
/*创建临时表*/
create table #tb(
No_ varchar(128) collate latin1_General_CS_AS,
Qty varchar(128) collate latin1_General_CS_AS,
Status1 varchar(100) collate latin1_General_CS_AS,
Status2 varchar(100) collate latin1_General_CS_AS,
Status3 varchar(100) collate latin1_General_CS_AS
)
declare db cursor for
select name from dbo.sysdatabases where name in('L0X32','L0X23','L0X25','L0902','L0205','L0803','L0208','L0B04')
--like 'L0%' and Status<>528 order by name
open db
fetch next from db into @db
while @@fetch_status=0
begin
set @cnt = @cnt+1
set @sql =' declare c cursor for
select name from '+@db+'..sysobjects where name<>''dtproperties''
and name like ''%$'+@tablename+''''
exec (@sql)
open c
fetch next from c into @tb
while @@fetch_status=0
begin
set @sql='Insert into #tb(No_,Qty,Status1,Status2,Status3)
select '''+@db+''',[No_],[Description],[Vendor No_],[Blocked]
from '+@db+'..'+'['+@tb+'] where [No_] in(''0887280107'',''0887280108'',''0887280109'')'
print @sql
exec (@sql)
fetch next from c into @tb
end
close c
deallocate c
fetch next from db into @db
end
close db
deallocate db
select @cnt
select * from #tb
drop table #tb