selete a.id 
from a
where exists (select 1 from b where a.id like '%'+b.id+'%')

解决方案 »

  1.   

    谢谢,不过like不能前后都跟字段名称。这样写不行
      

  2.   

    我用了可以啊?
    上面select 写错了,写成了selete。
    用:
    selete a.id 
    from a
    where exists 
       (select 1 from b where patindex('%'+b.id+'%',a.id) is not null)
    也可以。
      

  3.   

    谁说不能这样用?
    可能是你的id是int的问题吧。
    你转换成varchar
    这样:
    selete a.id 
    from a
    where exists (select 1 from b where convert(varchar(10),a.id) like '%'+convert(varchar(10),b.id)+'%')
      

  4.   

    对哦,我刚才在query中调试的时候还改了,结果copy过来的时候又忘改了。