create proc 过程名
@条件 varchar(8000)
as
exec('select fld1,fld2,fld3,fld4, ... from table1 where '+@条件+fld1 in (SELECT fld1 From table2 where '+@条件)

解决方案 »

  1.   

    没有更好的办法,SQL中的变量肯定是不能超过8000的长度的。
      

  2.   

    create proc 过程名
    @条件 varchar(8000)
    as
    exec('select fld1,fld2,fld3,fld4, ... from table1 where '+@条件+' fld1 in (SELECT fld1 From table2 where '+@条件)
      

  3.   

    create proc 过程名
    @条件 text
    as
    exec('select fld1,fld2,fld3,fld4, ... from table1 where '+@条件+' fld1 in (SELECT fld1 From table2 where '+@条件)
      

  4.   

    原来是参数定义错了:nvarchar(1000),结果传入的参数长度就只能很短。谢谢各位。
    结账。