Reputation: 896
I have the below code which needs a case condition based on the parameter.. IS this achievable? how to use the sql for this type.. I dont see any varaiation method to do this without the case
BEGIN
DECLARE @INPUT AS VARCHAR(256)
set @input = 'NASS'
SELECT
sum(TRY_PARSE(DV.[ERSDataValues_AttributeValue1] as decimal)) AS NEWVALUE
FROM [VegetablesCoSD-Full].[CoSD].[ERSDataValues] DV LEFT JOIN [CoSD]. [ERSTimeDimension_LU] TD
ON DV.ERSDataValues_ERSTimeDimension_ID = TD.ERSTimeDimension_ID
WHERE DV.ERSDataValues_ERSStatisticType_ID1 = 45 AND
DV.ERSDataValues_ERSCommodity_ID = 519 AND
DV.ERSDataValues_ERSGeography_ID = 3346 AND
DV.ERSDataValues_ERSUnit_ID1 = 89 AND
TD.ERSTimeDimension_TimeDimensionType_ID = 11 and
CASE
when @INPUT = 'NASS' THEN
TD.ERSTimeDimension_Month in
('1','2','3','4','5','6','7','8','9','10','11','12')
WHEN @INPUT = 'BLS' THEN
TD.ERSTimeDimension_Month IN('JAN','FEB')
END
Upvotes: 2
Views: 68
Reputation: 1464
You can use OR
instead, like this:
AND
( (@INPUT = 'MASS' AND TD.ERSTimeDimension_Month in ('1','2','3','4','5','6','7','8','9','10','11','12'))
OR
(@INPUT = 'BLS' AND TD.ERSTimeDimension_Month IN('JAN','FEB')
)
Upvotes: 4