27,579
社区成员
发帖
与我相关
我的任务
分享
if OBJECT_ID('fun_mu') is not null drop function fun_mu
go
create function fun_mu(@tb varchar(100),@text varchar(8000))
returns varchar(max)
as
begin
declare @sql varchar(max)
select @sql=ISNULL(@sql+' or ','union all select '''+OBJECT_NAME(object_id)+''' from '+OBJECT_NAME(object_id)+' where 1=1 and ')+t1.name+' = '''+@text+''''
from sys.columns t1
inner join sys.types t2 on t1.system_type_id=t2.system_type_id
where OBJECT_NAME(object_id)=@tb and (t2.name like '%char')
return @sql+' having count(1)=1'
end
go
declare @sql varchar(max)
select @sql=isnull(@sql+'
','')+dbo.fun_mu(name,'20141024165032914')
from sys.tables t1
inner join sys.partitions t2 on t1.object_id=t2.object_id and t2.index_id in (0,1) and t2.rows>0
--print stuff(@sql,1,10,'')
exec stuff(@sql,1,10,'')