我有一个表的字段为ProductIdList,其值格式为11,24,28,32productIdlist11,24,28,32
10,24,27
24,32,54,73,75
05,08,25我想将该字段值中包涵了24的记录查询出来,最好能用一句SQL完成。

解决方案 »

  1.   

    access中可以用select * from table where instr(1,productidlist,24) 这种方式来查询,但是SQL中不行。
      

  2.   

    declare @t table(productIdlist varchar(20))
    insert into @t select '11,24,28,32'
    union all select '10,24,27'
    union all select '24,32,54,73,75'
    union all select '05,08,25'
    union all select '05,08,25,244'declare @i int
    set @i=24
    select * from @t where charindex(','+cast(@i as varchar)+',',productIdlist)>0
      

  3.   

    SELECT * FROM table WHERE CHARINDEX(',24,',','+RroductIDList+',')>0
      

  4.   

    试试
    select * from table1 where productIdlist like'%24%'
      

  5.   

    --前面写的有问题,改一下
    declare @t table(productIdlist varchar(20))
    insert into @t select '11,24,28,32'
    union all select '10,24,27'
    union all select '24,32,54,73,75'
    union all select '05,08,25'
    union all select '05,08,25,244'declare @i int
    set @i=24
    select * from @t where charindex(','+cast(@i as varchar)+',',','+productIdlist+',')>0
      

  6.   

    select * from table1 
    where productIdlist like'%,24,%' or productIdlist like'24,%' or productIdlist like'%,24' 楼上也是一种好方法!!
      

  7.   

    declare @t table(productIdlist varchar(20))
    insert into @t select '11,24,28,32'
    union all select '10,24,27'
    union all select '24,32,54,73,75'
    union all select '05,08,25'
    union all select '05,08,25,244'
    union all select '05,08,25,24'declare @i int
    set @i=24
    select * from @t where charindex(','+cast(@i as varchar)+',',','+productIdlist+',')>0--修改以后应该可以了