字段 Tid 字符串类型,
值: 1,2,3,5
2,6,13,
3,7
要求以逗号隔开把数据中带 3 的数据读取出来,第2条值是13不算
即要得到第1条与第3条数据
数据库是Access的,。
------解决方案--------------------
- SQL code
select * from tab where Tid like '%3,%'
------解决方案--------------------
access啊、、语法好像不一样哦。。
------解决方案--------------------
sorry,1楼有bug,修正如下,
- SQL code
create table lin(Tid varchar(10))insert into linselect '1,2,3,5' union allselect '2,6,13' union allselect '3,7'select * from lin where Tid like '%,3,%' or Tid like '3,%'Tid----------1,2,3,53,7(2 row(s) affected)
------解决方案--------------------
select * from tab where Tid like '%3,%'
--or
select * from tab where charindex ('3,',Tid)>0
自己试下!!
------解决方案--------------------
- SQL code
--ACCESS中貌似是这样的select * from tablename where Instr(','+Tid+',',',3,')>0
------解决方案--------------------
- SQL code
if OBJECT_ID('tb')is not nulldrop table tbgocreate table tb(Tid varchar(10))insert into tbselect '1,2,3,5' union allselect '2,6,13' union allselect '2,6,13' union allselect '2,6,13' union allselect '2,6,3' union allselect '3,7'select * from tb where Tid like '%,3,%' or Tid like '3,%'or Tid like '%,3'(6 行受影响)Tid----------1,2,3,52,6,33,7(3 行受影响)
------解决方案--------------------
以3结尾的你没考虑到。。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
select * from lin
where Tid like '%,3,%' or Tid like '3,%' or Tid like '%,3'
------解决方案--------------------
- SQL code
if OBJECT_ID('tb')is not nulldrop table tbgocreate table tb(Tid varchar(10))insert into tbselect '1,2,3,5' union allselect '2,6,13' union allselect '2,6,13' union allselect '2,6,13' union allselect '2,6,3' union allselect '3,7'select * from tb where Tid like '*,3,*' or Tid like '3,*'or Tid like '*,3'(6 行受影响)Tid----------1,2,3,52,6,33,7(3 行受影响)