select * from table1 where userids like '2%'

解决方案 »

  1.   

    select * from  ta where charindex('2,', userids)<>0
    --注意:下面的写法是不对的, 楼上的也不行.
    --select * from ta where userids like '%2%'
      

  2.   

    select * from table1 where userids like '2%' or userids like '%2%' or  userids like '%2'
      

  3.   

    这样最好啦,
    select * from table1 where charindex ('2',userids )!=0
      

  4.   

    select * from ta where userids like '%2%'
    老大们解释一下,这样的为什么不行啊?
      

  5.   

    to  huohw:
    ID  UserIds
    1    2,3,4,
    2     5,1
    3     2,
    4     1, 2,
    5     1, 12,
    找出userids字段含有2的记录,我想结果应该是:
    1     2,3,4,
    3     2,
    4     1, 2,
      

  6.   

    --测试环境
    declare @t table(ID int identity(1,1),UserIds varchar(20))
    insert into @t select '2,3,4'
    union all select '5,1'
    union all select '2,'
    union all select '1,2,'
    union all select '1, 12,'--执行查询
    select * from @t where charindex(',2,',','+UserIds+',')>0--结果ID          UserIds              
    ----------- -------------------- 
    1           2,3,4
    3           2,
    4           1,2,(所影响的行数为 3 行)
      

  7.   

    select * from ta where userids like '%,2,%' or userids like '2,%'
      

  8.   

    如此:
    select * from table1 where userids like '%,2,%' or userids like '2,%' or userids like '%,2'
      

  9.   

    --charindex(str2,str1)
    在str1中寻找str2是否存在