我有以下用于存储过程的查询。我试图简化 CASE 语句中的逻辑。具体来说,我想将产品嵌套在用户组中。
SELECT DCMNumber,
SUM(CONVERT(INT, CurrentlyAssigned)) AS PriorAssigned
FROM dbo.cauAssignedClaim WITH(NOLOCK)
WHERE RecordType = 'A'
AND ([Status] <> 'DE' OR [Status] IS NULL)
AND DATEADD(dd, 0, DATEDIFF(dd, 0, EntryDate))
BETWEEN
CASE
WHEN Product IN('LTD', 'LTDCP') AND @UserGroup = '' OR @UserGroup = 'NONE'
THEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-30))
WHEN Product IN('STD', 'STDCP', 'SALCN', 'STAT', 'OFFOV') AND @UserGroup = '' OR @UserGroup = 'NONE'
THEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-14))
WHEN Product IN('LTD', 'LTDCP') AND @UserGroup IN('SSAT', 'TCMS')
THEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-7))
WHEN Product IN('STD', 'STDCP', 'SALCN', 'STAT', 'OFFOV') AND @UserGroup IN('Appeals', 'DMS', 'Life', 'WOP', 'IWOP')
THEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-7))
END
AND DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()-1))
GROUP BY [Status], DCMNumber