I am trying to get the following code to work within a ssrs dataset:
SELECT COUNT(workorderID) AS WO_Total, YEAR(dateCreated) AS RAAG_Year, franchiseID
FROM WRK_ORDER
WHERE (MONTH(dateCreated) = CASE @Month WHEN NULL THEN
(SELECT MONTH(MAX(dateCreated)) AS mMonth
FROM WRK_ORDER AS WRK_ORDER_1
WHERE (YEAR(dateCreated) = @RAAG_Year) AND (franchiseID = @franchise)) ELSE @Month END)
GROUP BY franchiseID, YEAR(dateCreated)
But I continue to get 'Incorrect Parameter' error.
I know it has something to do with the CASE statement and the @Month parameter...but I can not figure out what it is?
Basically I want to check the parameter and if it is NULL then use the value from the subquery else use the parameter value.
Anybody done something like this?
SELECT COUNT(workorderID) AS WO_Total, YEAR(dateCreated) AS RAAG_Year, franchiseID
FROM WRK_ORDER
WHERE (MONTH(dateCreated) = CASE @Month WHEN NULL THEN
(SELECT MONTH(MAX(dateCreated)) AS mMonth
FROM WRK_ORDER AS WRK_ORDER_1
WHERE (YEAR(dateCreated) = @RAAG_Year) AND (franchiseID = @franchise)) ELSE @Month END)
GROUP BY franchiseID, YEAR(dateCreated)
But I continue to get 'Incorrect Parameter' error.
I know it has something to do with the CASE statement and the @Month parameter...but I can not figure out what it is?
Basically I want to check the parameter and if it is NULL then use the value from the subquery else use the parameter value.
Anybody done something like this?