如何判断一个表的某一列是否包含另外一个表的某一列?
比如表A的列rmtypelist内容是“STW,BKN,GFN”表B的列kat内容是“BKN”
那么应该就算包含
我这样写:
…………A.rmtypelist like '%'+b.kat+'%'
可是这样不一定取得出来:
当KAT列是“STW”或者是“BKN”或者是“GFN”的时候,这三种情况下,不是都能判断成功。求助。谢谢各位

解决方案 »

  1.   

    --try
    where charindex(','+b.kat+',',','+A.rmtypelist +',')>0
      

  2.   

    立刻去试。非常感谢wufeng4552的无私帮助!
      

  3.   

    很遗憾,取不出来。换成在同一个数据库内测试,也不行
    数据库名字 GRES2
    列KAT 内容 “STW”
    列RTXT 内容“STW,SKN”select * from gres2 where charindex(','+kat+',',','+rtrim(rtxt)+',')>0结果为空很奇怪,应该可以的
      

  4.   

    --try 你要什么结果?
    select * 
    from gres2 a,gres2 b
    where charindex(','+a.kat+',',','+rtrim(b.rtxt)+',')>0
      

  5.   


    select * from a,b where charindex(','+a.kat+',',','+b.RTXT+',',1) >0
      

  6.   


    这两列是什么类型的?看看前后是否有空格,试试select * from gres2 where charindex(','+ltrim(rtrim(kat))+',',','+ltrim(rtrim(rtxt))+',')>0
      

  7.   

    如果这样情况。like就应该可以