34,587
社区成员
发帖
与我相关
我的任务
分享
--不好意思 掉了个)号
declare @name nvarchar(100)
declare cur cursor for select name from sysobjects where type = 'U'
open cur
fetch next from cur into @name
WHILE @@FETCH_STATUS = 0
begin
declare @sql nvarchar(500),@s varchar(5000)
set @s =''
set @sql='select @s=isnull(@s+''+'','''')+'''''',''''''+''+cast(isnull([''+name+''],'''''''') as varchar)'' from syscolumns where id=object_id('''+@name+''') and xtype in(175,239,99,231,35,167) '
exec sp_executesql @sql,N'@s varchar(5000) out',@s out
if len(@s) > 0
exec('if exists(select 1 from (select '+ @s+' as col from ['+@name+']) b where 用户编号 in(''001'',''002'')) print '''+@name+'''')
fetch next from cur into @name
end
close cur
DEALLOCATE cur
declare @name nvarchar(100)
declare cur cursor for select name from sysobjects where type = 'U'
open cur
fetch next from cur into @name
WHILE @@FETCH_STATUS = 0
begin
declare @sql nvarchar(500),@s varchar(5000)
set @s =''
set @sql='select @s=isnull(@s+''+'','''')+'''''',''''''+''+cast(isnull([''+name+''],'''''''') as varchar)'' from syscolumns where id=object_id('''+@name+''') and xtype in(175,239,99,231,35,167) '
exec sp_executesql @sql,N'@s varchar(5000) out',@s out
if len(@s) > 0
exec('if exists(select 1 from (select '+ @s+' as col from ['+@name+']) b where 用户编号 in(''001'',''002'') print '''+@name+'''')
fetch next from cur into @name
end
close cur
DEALLOCATE cur
declare @sql nvarchar(4000)
select @sql=isnull(@sql,'')+'select * from '+a.name+' where 用户编号 in(''001'',''002'') '
from sysobjects a inner join syscolumns b on a.id=b.id where type='U' and b.name='用户编号'
exec(@sql)
declare @sql nvarchar(4000)
select @sql=isnull(@sql,'')+'select * from '+a.name+' where 用户编号 in(''001'',''002'') '
from sysobjects a inner join syscolumns b on a.where type='U' and b.name='用户编号'
exec(@sql)
select tbname from
(select '表A' as tbname,用户编号 from 表A
union all
select '表B' as tbname,用户编号 from 表B
union all
......) t where 用户编号 in ('001','002')