日期:2014-05-18 浏览次数:20446 次
select * from tableA where 1 = 1 and id like '%30%'
------解决方案--------------------
select * from tableA
where 1 = 1
and id like '30%'
------解决方案--------------------
select * from tableA where 1 = 1 and ',30,' like ','+ltrim(id)+','
------解决方案--------------------
in不是用来进行模糊查询的~
------解决方案--------------------
select * from tableA where 1 = 1 and charindex(',30,' ,','+ltrim(id)+',')>0
------解决方案--------------------
in 后面跟的最小单位是一列。。。不是一列中的某个值
------解决方案--------------------
if object_id('tableA') is not null drop table tableA go create table tableA ( id varchar(20) ) go insert into tableA select '30' union all select '40' union all select '41' union all select '30,40,41' go select * from tableA where ','+id+',' like '%,30,%' /* (4 行受影响) id -------------------- 30 30,40,41 (2 行受影响) */
------解决方案--------------------
select * from tableA
where id like '30%'
这样写才行 因为第四个本身就是一个字段形式的