日期:2014-05-18 浏览次数:20487 次
ALTER PROCEDURE [dbo].[PROC_EAPS_GetJobReport] @in_ph Nvarchar(20), @in_pm Nvarchar(60), @in_gxmc Nvarchar(60), @in_usID nvarchar(10) AS BEGIN declare @sql nvarchar(4000) DECLARE @STR VARCHAR(3000) SET @STR='' SELECT @STR=EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = @in_usID EXEC(' SELECT [JO002] ,[JO003] ,[JO005] ,[JO015] ,[JO027] ,[JO013] ,[JO014] ,[JO017] ,[JO021] ,[JO028] ,[JO022] ,[JO023] ,[JO024] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+')') END
AND JO002 LIKE CASE WHEN @in_ph = '' THEN JO002 ELSE '%'+ @in_ph +'%' END AND JO003 LIKE CASE WHEN @in_pm = '' THEN JO003 ELSE '%'+ @in_pm +'%' END AND JO005 LIKE CASE WHEN @in_gxmc = '' THEN JO005 ELSE '%'+ @in_gxmc +'%' END
EXEC(' SELECT [JO002] ,[JO003] ,[JO005] ,[JO015] ,[JO027] ,[JO013] ,[JO014] ,[JO017] ,[JO021] ,[JO028] ,[JO022] ,[JO023] ,[JO024] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+') 'AND JO002 LIKE CASE WHEN '+ @in_ph + ' = '' THEN JO002 ELSE '%' '+ @in_ph +''%' END AND JO003 LIKE CASE WHEN '+@in_pm +' = '' THEN JO003 ELSE '%''+ @in_pm +''%' END AND JO005 LIKE CASE WHEN '+ @in_gxmc +' = '' THEN JO005 ELSE '%''+ @in_gxmc +''%' END ')
------解决方案--------------------
错了,应该是:
EXEC(' SELECT [JO002] ,[JO003] ,[JO005] ,[JO015] ,[JO027] ,[JO013] ,[JO014] ,[JO017] ,[JO021] ,[JO028] ,[JO022] ,[JO023] ,[JO024] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+') AND JO002 LIKE CASE WHEN '+ @in_ph + ' = '' THEN JO002 ELSE '%' '+ @in_ph +''%' END AND JO003 LIKE CASE WHEN '+@in_pm +' = '' THEN JO003 ELSE '%''+ @in_pm +''%' END AND JO005 LIKE CASE WHEN '+ @in_gxmc +' = '' THEN JO005 ELSE '%''+ @in_gxmc +''%' END ')
------解决方案--------------------
' SELECT [JO002] ,[JO003] ,[JO005] ,[JO015] ,[JO027] ,[JO013] ,[JO014] ,[JO017] ,[JO021] ,[JO028] ,[JO022] ,[JO023] ,[JO024] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+') AND JO002 LIKE CASE WHEN ' + @in_ph + ' = '''' THEN JO002 ELSE ''%' + @in_ph + '%'' END AND JO003 LIKE CASE WHEN ' + @in_pm + ' = '''' THEN JO003 ELSE ''%' + @in_pm + '%'' END AND JO005 LIKE CASE WHEN ' + @in_gxmc + ' = '''' THEN JO005 ELSE ''%' + @in_gxmc +'%'' END'
------解决方案--------------------
declare @execsql nvarchar(4000) DECLARE @STR VARCHAR(3000)='1' DECLARE @in_ph Nvarchar(20)='' SET @execsql=' SELECT [JO002] ,[JO003] ,[JO005] ,[JO015] ,[JO027] ,[JO013] ,[JO014] ,[JO017] ,[JO021] ,[JO028] ,[JO022] ,[JO023] ,[JO024] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+') '+ 'AND JO002 LIKE CASE WHEN '+char(39)+@in_ph +char(39)+'= '+char(39)+char(39)+' THEN JO002 ELSE '+char(39)+char(37)+@in_