select * from 表 where 字段 like '%adsfsfd%'
解决方案 »
- 求一存储过程,关于两个表的记录复制.
- 如何转换代码?
- DELETE与TRUNCATE TABLE与游标的诡异问题
- sql05MSDE还用打SP4吗?可以在内网中连吗?
- union 老生常谈 合并表
- 有没有什么办法让查询真正执行时,查询到匹配的一条就直接返回结果集,而不是先全查出然后选1条.
- 触发器问题,急!在线等
- 请教一个简单的sql语句问题
- 小型自选商场数据库设计
- 各位好,ADO高手好,谁用过邓振波 写的,ADO封装的两个类,小弟能连上SQL SERVER,但是老是打不开记录集
- (如图)创建存储过程时突然发现NewID() 似乎不能直接作为存储过程的参数传入,不知道哪位高人能给个解释~~ 3Q
- 请教各位:下面这种语句能否使用索引?Like '__1%'
--搜索所有库表的某个值
--创建过程,参数是你要查询的字符串
create proc proc_selectall
@s varchar(50)--你的关键字
as
begin
declare @sql varchar(8000),@where varchar(8000)
declare cursor_tb cursor for
select name from sysobjects where xtype='u'
declare @name varchar(50)
open cursor_tb
fetch next from cursor_tb
into @name
while @@FETCH_STATUS = 0
begin
select @sql=isnull(@sql+' or ','')+'ltrim(['+name+'])='''+@s+''''
from syscolumns where id=object_id(@name)
set @where=replace(@sql,'''','''''')
exec('if exists(select 1 from ['+@name+'] where '+@sql+') exec(''select * from ['+@name+'] where '+@where+''')')
select @sql=null
fetch next from cursor_tb
into @name
end
close cursor_tb
deallocate cursor_tb
end
go
--举例
if object_id('tb') is not null
drop table tb
if object_id('ta')is not null
drop table ta
go
create table tb(s varchar(50))
insert into tb select 'abc'
create table ta(s varchar(50))
insert into ta select 'abc'
go
exec proc_selectall 'abc'
declare @str varchar(100)
set @str='adsfsfd' --要搜索的字符串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--如果能查询到它所在表和它所在字段,构造更新语句就很方便了.
然后打开ultra edit去查61736466
比如这个嵌套exec中的红色部分。