Link to home
Start Free TrialLog in
Avatar of BobRosas
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.LastTermDate) 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
ASKER CERTIFIED SOLUTION
Avatar of ValentinoV
ValentinoV
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BobRosas
BobRosas

ASKER

I actually didn't need the MAX.  I only put it in because I did not want to group by the date.  But I took it out and it works GREAT!  Thank you so much!
Thank you so much!