请教 为何查询不到数据?
tableA
30
40
41
30,40,41
select * from tableA
where 1 = 1
and id in (30)
为什么只查处第一条数据呢?第四条数据没出来?
[解决办法]
都in了 肯定查不出来喽
[解决办法]
try this,
select * from tableAwhere 1 = 1and id like '%30%'
[解决办法]
select * from tableA
where 1 = 1
and id like '30%'
[解决办法]
select * from tableAwhere 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 tableAgocreate table tableA( id varchar(20))goinsert into tableAselect '30' union allselect '40' union allselect '41' union allselect '30,40,41'goselect * from tableA where ','+id+',' like '%,30,%'/*(4 行受影响)id--------------------3030,40,41(2 行受影响)*/
[解决办法]
select * from tableA
where id like '30%'
这样写才行 因为第四个本身就是一个字段形式的