ITPub博客

首页 > 数据库 > 数据库开发技术 > 搜索某个字符串在那个表的那个字段中

搜索某个字符串在那个表的那个字段中

原创 数据库开发技术 作者:caixia615 时间:2007-02-12 15:03:35 0 删除 编辑

--搜索某个字符串在那个表的那个字段中

declare @str varchar(100)
set @str='White' --要搜索的字符串

declare @s varchar(8000)
declare tb cursor local for
select s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'')
print ''所在的表及字段: ['+b.name+'].['+a.name+']'''
from syscolumns a join sysobjects b on a.id=b.id
where b.xtype='U' and a.status>=0
and a.xusertype in(175,239,231,167)
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb

/*--测试结果

所在的表及字段: [authors].[au_lname]

--*/

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8591181/viewspace-899296/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 查询重复记录
请登录后发表评论 登录
全部评论
  • 博文量
    1255
  • 访问量
    57806977