declare @x varchar(100),@string varchar(800)
set @x="('1389','0736')"set @string="select pub_name from publishers where pub_id in "+@x exec(@string)

解决方案 »

  1.   

    liujianjun_(流星尔)说的我前边提到了,@string有最多不超过varchar(8000)的限制,我就是想办法除去这一限制,
    比如说:
    Set @string = @string + 'select * into #temptable ...'
    exec(@string)
    如果在直接写select * from #temptable是不行的,因为不再同一进程。
    所以只能挤在@string内.
      

  2.   

    SELECT  pub_name
      FROM  publishers
      WHERE  pub_id  in  (select pub_id from temp)
    temp中放你的查询信息
      

  3.   

    请sky_blue(蓝天)帮忙看看,这样写对吗?
    declare @x varchar(100)SET @x = '''1389'', ''0736'''select @x as test into #tempSELECT pub_name
    FROM publishers
    WHERE pub_id in (select test from #temp)
      

  4.   

    蓝天不是这样的意思。
    select '1389' as test into #temp
    insert into #temp(test) values('0736')SELECT  pub_name
      FROM  publishers
      WHERE  pub_id  in  (select  test  from  #temp)
      

  5.   

    也就是temp的表是
    test
    1389
    0736
      

  6.   

    有没有办法去除varchar(8000)的限制?比方说varchar(16000)
      

  7.   

    方法是好的,但我用不成,苦啊,我是开一个大的select框(也许有近200行,varchar字数近6000),将其中的各行组成111'',''222'',333...这样的一个大字串传入存储过程,(字串不能像111','222...这样存储过程会说参数过多)
    再存储过程中写
    set @x = @x+'select * from table where 条件 in ('''+参数+''')'
    ...所以@x受到8000限制
    如果不写@x这样,
    在存储过程中头上我就要再replace(参数,''''',''''',''',''')
    这样我又回到了我最初提出的问题..
    如果按蓝天的方法我就需要拆卸大字串再存入临时表,也许要做2000个insert
    还有如何在存储过程中拆这个字串,开销如何?
      

  8.   

    關於如何---------------------
    在存储过程中拆这个字串
    ---------------------方法很簡單,開銷很小!請看:http://www.csdn.net/expert/topic/508/508081.xml
      

  9.   

    或者看:http://www.itpub.net/showthread.php?s=&threadid=11308
    中的第二題。
      

  10.   

    試試下面 SELECT pub_name
     FROM publishers
     WHERE pub_id = '1389'
     union
     SELECT pub_name
     FROM publishers
     WHERE pub_id = '0736'或者是 SELECT pub_name
     FROM publishers
     WHERE (pub_id = '0736' or pub_id ='1386')
      

  11.   

    試試下面 SELECT pub_name
     FROM publishers
     WHERE pub_id = '1389'
     union
     SELECT pub_name
     FROM publishers
     WHERE pub_id = '0736'或者是 SELECT pub_name
     FROM publishers
     WHERE (pub_id = '0736' or pub_id ='1386')