select ID,name 
FROM A  
WHERE a.ID IN (
SELECT b.settings FROM b
WHERE b.id = 5
)b表settings字段内容"1,2,3,4,5"判断a表ID是否In 其中。运行报错:Operand type clash: text is incompatible with int有没有好的办法解决?谢谢

解决方案 »

  1.   

    declare @s varchar(500)
    set @s = SELECT b.settings FROM b WHERE b.id = 5
    select ID,name  
    FROM A   
    WHERE charindex(a.ID, @s) > 0
      

  2.   

    select * from A
    where charindex(','+rtrim(a.id)+',',(select b.settings from b where b.id=5))>0
      

  3.   

    试试select ID,name  
    FROM A  
    WHERE exists (
    SELECT 1 FROM b
    WHERE b.id = 5
    and ','+b.settings+',' like '%,'+a.ID+',%' 
    )