BobRosas
asked on
Use CASE statement results in WHERE
The following code is giving me the results I want except i have the date hard coded in the WHERE clause because the result of my CASE statement doesn't work. How do I substitute '4/2/12' with EndDate so it's not a static value?
SELECT COUNT(DeptID) AS Count, DeptID, CASE WHEN MAX(vw_HrIndividuals.LastT ermDate) IS NULL THEN GetDate() END AS EndDate
FROM vw_HrIndividuals
WHERE (@Date BETWEEN CONVERT(datetime, CONVERT(char(8), LastStartDate, 112)) AND '4/2/12')
GROUP BY DeptID
ORDER BY DeptID
SELECT COUNT(DeptID) AS Count, DeptID, CASE WHEN MAX(vw_HrIndividuals.LastT
FROM vw_HrIndividuals
WHERE (@Date BETWEEN CONVERT(datetime, CONVERT(char(8), LastStartDate, 112)) AND '4/2/12')
GROUP BY DeptID
ORDER BY DeptID
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much!
ASKER