How can I create a sql-server query that ignores 29-of February in a non-leap year and include 29-of February in leap year. (Assuming I have a column in a table with dates from 2000-01-01 to 2016-12-31 for example)
At the moment I have this but it completely removes the leap years.
SELECT uid, CONVERT(DATE,CAST(DATEPART(yyyy,day) AS VARCHAR(4))+'-'+
CAST([Month] AS VARCHAR(2))+'-'+
CAST(29 AS VARCHAR(2))) AS code_date, [29] AS code FROM [data]
WHERE DATEPART(mm,day) <> 2 AND NOT (ISDATE(CAST(DATEPART(yyyy,day) AS char(4)) + '0229') = 1)
However, I only want to remove all 29th of February in every year except a leap year.