如何判断一个表的某一列是否包含另外一个表的某一列?
比如表A的列rmtypelist内容是“STW,BKN,GFN”表B的列kat内容是“BKN”
那么应该就算包含
我这样写:
…………A.rmtypelist like '%'+b.kat+'%'
可是这样不一定取得出来:
当KAT列是“STW”或者是“BKN”或者是“GFN”的时候,这三种情况下,不是都能判断成功。求助。谢谢各位
比如表A的列rmtypelist内容是“STW,BKN,GFN”表B的列kat内容是“BKN”
那么应该就算包含
我这样写:
…………A.rmtypelist like '%'+b.kat+'%'
可是这样不一定取得出来:
当KAT列是“STW”或者是“BKN”或者是“GFN”的时候,这三种情况下,不是都能判断成功。求助。谢谢各位
where charindex(','+b.kat+',',','+A.rmtypelist +',')>0
数据库名字 GRES2
列KAT 内容 “STW”
列RTXT 内容“STW,SKN”select * from gres2 where charindex(','+kat+',',','+rtrim(rtxt)+',')>0结果为空很奇怪,应该可以的
select *
from gres2 a,gres2 b
where charindex(','+a.kat+',',','+rtrim(b.rtxt)+',')>0
select * from a,b where charindex(','+a.kat+',',','+b.RTXT+',',1) >0
这两列是什么类型的?看看前后是否有空格,试试select * from gres2 where charindex(','+ltrim(rtrim(kat))+',',','+ltrim(rtrim(rtxt))+',')>0