What is wrong with this SQL statement? I keep getting SelMonth and CurMonth are invalid columns, am I doing my Where clause wrong? Is the DATEPART causing a problem here?
SELECT TOP (5)
EName, EDate, EDateEnd,
DATEPART(month, EDate) AS SelMonth,
DATEPART(month, { fn CURDATE() }) AS CurMonth
FROM
Events
WHERE
(EDate >= { fn CURDATE() })
AND (SelMonth = CurMonth)
Thanks
You can’t use the SelMonth and CurMonth in the WHERE clause: