select * from 表 where id in (select id from 另一表)

解决方案 »

  1.   

    可是我需要我查询出的一组id存储在一个varchar 类型的字段中的
      

  2.   

    如何拆分呢?比如将如下结果集合
          id       name
           1        jjjj
           2        hhhh
           4        gggg
    我如何将 3个id 存入一个变量呢?
      

  3.   

    如:declare @s varchar(1000)select @s=@s+','+id from tset @s=stuff(@s,1,1,'')select * from other_table where id in(@s)
      

  4.   

    declare @id nvarchar(4000)
    set @id = ''
    select @id=@id+id from 表 
    print @id