我的SSRS中有一个使用SP的@AgentGroup
参数。
我想要做的是,如果参数传递值PREPB_STRSTR,NULL
,它还将显示空值。我考虑在where子句中添加OR @AgentGroup is null
,但如果参数只传递值PREPB_STRSTR
,它也会显示空数据。
DECLARE @DateTo date = '3/21/2017',
@DateFrom date = '3/21/2017',
@VHGroup nvarchar(max) = 'PREPB_STRSTR,NULL'
SELECT
[AgentIRACGroup]
,[CallOutCallID]
,[CallOutDateTime]
,[OutboundDuration]
,[CallOutNumber]
,[AgentName]
,[CallOutAgentID]
,[AgentGroup]
,[Outcome]
,[TalkTime]
FROM [AgentStatisticsEOD].[dbo].[IRAC_Data]
WHERE CONVERT(Date,[SCBCallDateTimeRequest]) BETWEEN @DateFrom AND @DateTo
AND [AgentGroup] collate database_default in (SELECT value from dbo.FnSplit(@VHGroup,',')) OR [AgentGroup] is null
即使[AgentGroup]
没有传递空值,我的查询也会始终显示空@Agentgroup
。
答案 0 :(得分:2)
解决它的最简单方法是添加另一个条件来检查参数是否实际包含单词NULL
:
DECLARE @DateTo date = '3/21/2017',
@DateFrom date = '3/21/2017',
@VHGroup nvarchar(max) = 'PREPB_STRSTR,NULL'
SELECT
[AgentIRACGroup]
,[CallOutCallID]
,[CallOutDateTime]
,[OutboundDuration]
,[CallOutNumber]
,[AgentName]
,[CallOutAgentID]
,[AgentGroup]
,[Outcome]
,[TalkTime]
FROM [AgentStatisticsEOD].[dbo].[IRAC_Data]
WHERE CONVERT(Date,[SCBCallDateTimeRequest]) BETWEEN @DateFrom AND @DateTo
AND [AgentGroup] collate database_default in (SELECT value from dbo.Split(@VHGroup,','))
OR
(',' + @VHGroup +',' LIKE '%,NULL,%'
AND [AgentGroup] is null
)