当前位置: 代码迷 >> Sql Server >> 求一简单SQL语句.该怎么处理
  详细解决方案

求一简单SQL语句.该怎么处理

热度:72   发布时间:2016-04-27 13:59:45.0
求一简单SQL语句.,.
字段 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结尾的你没考虑到。。

探讨
sorry,1楼有bug,修正如下,

SQL code

create table lin
(Tid varchar(10))

insert into lin
select '1,2,3,5' union all
select '2,6,13' union all
select '3,7'


select * from lin
where Tid like '%……

------解决方案--------------------
探讨
SQL code


declare @T table
(Tid VARCHAR(10))
insert into @T
select '1,2,3,5' union all
select '2,6,13' union all
select '3,7'

select * from @T WHERE CHARINDEX(',3,',','+Tid+',')>0
/*
Ti……

------解决方案--------------------
探讨
以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 行受影响)
  相关解决方案