当前位置: 代码迷 >> Sql Server >> not in 后面怎么跟参数
  详细解决方案

not in 后面怎么跟参数

热度:96   发布时间:2016-04-27 20:45:51.0
not in 后面如何跟参数?
我有一个sql语句:

...   where   detail   not   in   ( '误工费 ', '加急费 ')

如何把   误工费,加急费   [email protected],@b,如果参数数目不定,又改如何处理?

------解决方案--------------------
作成存储过程参数

create proc @s varchar(100)
as
exec ( 'select .... where detail not in( '[email protected]+ ') ')
------解决方案--------------------
declare @S varchar(4000)
set @S=111,222,33 --如果你是这样传的话
exec ( 'select * from [table] where detail not in( ' ' '+replace(@S, ', ', ' ' ', ' ' ')+ ' ' ') ')

------解决方案--------------------
declare @SQL varchar(8000)
declare @a varchar(20)
declare @b varchar(20)

set @a= '误工费 '
set @b= '加急费 '
set @SQL= '... where detail not in ( ' ' '[email protected]+ ' ' ', ' ' '[email protected]+ ' ' ' '
exec(@SQL)

------解决方案--------------------
将数目不定的参数转成 aas,dff,ddd 的形式 [email protected]
where charindex( ', '+rtrim(detail)+ ', ' , ', '[email protected]+ ', ')> 0
如果有前台直接在前台生成not in ( 'aas ', 'dff ', 'ddd ')语句即可
  相关解决方案