select * from 表
where charindex(',3,',','+符合的id+',')>0

解决方案 »

  1.   

    declare @t table(符合的id varchar(20),姓名 varchar(10))
    insert into @t select '1,2,3','张1'
    union all select '1,3,5','张2'
    union all select '1,7,15','张3'select * from @t
    where charindex(',3,',','+符合的id+',')>0--
    /*
    符合的id                姓名         
    -------------------- ---------- 
    1,2,3                张1
    1,3,5                张2(所影响的行数为 2 行)
    */
      

  2.   

    select * from b
    where charindex(符合的id,a)>0
      

  3.   

    select * from b where [符合的id] like '3,%' or [符合的id] like '%,3,%' or [符合的id] like '%,3' or [符合的id] = '3'
      

  4.   

    select * from b
    where charindex(符合的id,a)>0
      

  5.   

    select * from table where charindex('3',id)>0 or charindex('3',姓名)>0
      

  6.   

    呵呵,不好意思;函数参数写错了;charindex(a,符合的id)>0
      

  7.   

    --楼主上面的可能有问题
    --因为共要考虑该变量在字段值中的三个位置
    declare @str varchar(1000)
    set @str='3'declare @strTemp1 varchar(100)
    declare @strTemp2 varchar(100)
    declare @strTemp3 varchar(100)
    set @strTemp1=@str +','
    set @strTemp2=','+@str +','
    set @strTemp3=','+@str select *from #temp
    where charindex(@strTemp1,tConten)>0
    union 
    select *from #temp
    where charindex(@strTemp2,tConten)>0
    union 
    select *from #temp
    where charindex(@strTemp3,tConten)>0