我有一个sql语句:... where detail not in ('误工费','加急费')如何把 误工费,加急费 改成参数@a,@b,如果参数数目不定,又改如何处理?

解决方案 »

  1.   

    作成存储过程参数create proc @s varchar(100)
    as
    exec ('select .... where detail not in('+@s+')')
      

  2.   

    写一个临时表
    放入条件参数where detail not in (select xxx from 临时表)
      

  3.   

    declare @S varchar(4000)
    set @S=111,222,33 --如果你是这样传的话
    exec ('select * from [table] where detail not in('''+replace(@S,',',''',''')+''')')
      

  4.   

    declare @SQL varchar(8000)
    declare @a varchar(20)
    declare @b varchar(20)set @a='误工费'
    set @b='加急费'
    set @SQL='... where detail not in ('''+@a+''','''+@b+''''
    exec(@SQL)
      

  5.   

    将数目不定的参数转成 aas,dff,ddd 的形式 用一个参数@a处理
     where charindex(','+rtrim(detail)+','  ,  ','+@a+',')>0
    如果有前台直接在前台生成not in ('aas','dff','ddd')语句即可
      

  6.   

    将数目不定的参数转成   aas,dff,ddd   的形式   用一个参数@a处理 
      where   charindex( ', '+rtrim(detail)+ ', '     ,     ', '+@a+ ', ')> 0 
    --------------------------------------------------------------------------
    好办法,不知性能如何。