是不是这个意思? declare @t table([ID] int identity(1,1),number varchar(50)) insert @t(number) select '1234' union all select '1234,981234000,123456' union all select '123422,981234000,12345611'select * from @tselect * from @t where charindex(','+'1234'+',',','+number+',')>0/*(所影响的行数为 3 行)ID number ----------- -------------------------------------------------- 1 1234 2 1234,981234000,123456 3 123422,981234000,12345611(所影响的行数为 3 行)ID number ----------- -------------------------------------------------- 1 1234 2 1234,981234000,123456(所影响的行数为 2 行)*/
like 123% 你这样子 试试 ! 多试试几种组合。
select * from tb where charindex(','+'1234'+',',','+ziduan+',')>0
到现在我还不明白楼主想干嘛? 如果你就是想查1234, select * from table where id='1234' 如果你想查包含1234的: select * from table where id like '%1234%' 如果你想查1234开头的 select * from table where id like '1234%' 如果你还要判断" , "符号建议用变量或者存储过程
1234
1234,981234000,123456
这两条记录,但是用like查询的话就会查出 12345678等数据
请问楼主你是想查出什么呢?不明白你要查什么,你用like % %当然是包含的全都出来的,你快把问题说清楚一点吧!
declare @t table([ID] int identity(1,1),number varchar(50))
insert @t(number) select '1234'
union all select '1234,981234000,123456'
union all select '123422,981234000,12345611'select * from @tselect *
from @t
where charindex(','+'1234'+',',','+number+',')>0/*(所影响的行数为 3 行)ID number
----------- --------------------------------------------------
1 1234
2 1234,981234000,123456
3 123422,981234000,12345611(所影响的行数为 3 行)ID number
----------- --------------------------------------------------
1 1234
2 1234,981234000,123456(所影响的行数为 2 行)*/
like 123%
你这样子 试试 ! 多试试几种组合。
到现在我还不明白楼主想干嘛?
如果你就是想查1234,
select * from table where id='1234'
如果你想查包含1234的:
select * from table where id like '%1234%'
如果你想查1234开头的
select * from table where id like '1234%'
如果你还要判断" , "符号建议用变量或者存储过程