参考这个页面
http://topic.csdn.net/u/20090903/11/bd9026f2-eb0f-491b-ba9e-22d197efe66b.html?1343759658
tb
id name type
1  dd  1,2
2  ddd  1
3  ee    2用
SELECT * FROM TB WHERE CHARINDEX(','+LTRIM(ID)+',',','+TYPE+',')>0为什么会把第一行省略.少读了一行.这是怎么回事呀,跪求高手解答!

解决方案 »

  1.   

    SELECT * FROM TB WHERE CHARINDEX(','+LTRIM(1)+',',','+TYPE+',')>0 ??
    你可修改下
      

  2.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(我是小F,向高手学习)
    -- Date    :2009-09-03 11:24:34
    -- Verstion:
    --      Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
    --    Nov 24 2008 13:01:59 
    --    Copyright (c) 1988-2005 Microsoft Corporation
    --    Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([id] int,[name] varchar(3),[type] varchar(3))
    insert [tb]
    select 1,'dd','1,2' union all
    select 2,'ddd','1' union all
    select 3,'ee','2'
    --------------开始查询--------------------------
    select * from tb where charindex(','+'1'+',',','+type+',')>0
    ----------------结果----------------------------
    /* id          name type
    ----------- ---- ----
    1           dd   1,2
    2           ddd  1(2 行受影响)
    */
      

  3.   

    type 中“,”后面有空格?