34,590
社区成员
发帖
与我相关
我的任务
分享
declare @t table(id int,name varchar(50))
insert into @t
select 1,'A' union all
select 2,'BB' union all
select 3,'C' union all
select 4,'E' union all
select 5,'GG' union all
select 6,'ABC'
select id, charindex(name,b) pos from (select id,name,'械在地在遥A在夺地有地在' b from @t) tmp where charindex(name,b)>0
/*
id pos
----------- -----------
1 6
(1 行受影响)
*/
---------------------------------
-- Author: htl258(Tony)
-- Date : 2009-07-08 16:22:12
---------------------------------
--> 生成测试数据表-tb
if not object_id('tb') is null
drop table tb
Go
Create table tb([id] int,[name] nvarchar(3))
Insert tb
select 1,'A' union all
select 2,'BB' union all
select 3,'C' union all
select 4,'E' union all
select 5,'GG' union all
select 6,'ABC'
Go
--Select * from tb
-->SQL查询如下:
declare @s varchar(200)
set @s='械在地在遥A在夺地有地在'
select id from tb where charindex([name],@s)>0
/*
id
-----------
1
(1 行受影响)
*/
declare @str varchar(100)
set @str = '一段文件'
select *
from tb
where charindex(name,@str) > 0;
select *
from tb
where charindex(name,'械在地在遥A在夺地有地在')>0