1    001,002,1001,
2    002,1001,
有两条记录,我用 like '%001%' 会把两条记录都查询出来1001也包括进来了,,只想要包含 001 的记录,请问要怎么处理??

解决方案 »

  1.   

    where ','+col+',' like '%,001,%'
      

  2.   

    或:
    where charindex(',001,',','+col+',')>0
      

  3.   

    like ',' + col + ',' like '%,0001,%'
      

  4.   

    或者:
    where charindex(',001,',','+col+',')>0
      

  5.   


    --------------------SQL Server数据格式化工具-------------------
    ---------------------------------------------------------------
    -- DESIGNER :happycell188(喜喜)
    --       QQ :584738179
    -- Development Tool :Microsoft Visual C++ 6.0    C Language 
    -- FUNCTION :CONVERT DATA TO T-SQL
    ---------------------------------------------------------------
    -- Microsoft SQL Server  2005
    -- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
    ---------------------------------------------------------------
    ---------------------------------------------------------------use test
    go
    if object_id('test.dbo.tb') is not null drop table tb
    -- 创建数据表
    create table tb
    (
    id int,
    value char(15)
    )
    go
    --插入测试数据
    insert into tb select 1,'001,002,1001,'
    union all select 2,'002,1001,'
    go
    --代码实现
    select * from tb where charindex(',001,',','+value)>0
    /*测试结果id value
    ---------------------
    1 001,002,1001,(1 行受影响)
    */