Your logic looks good and will work as is.
An alternative that simplifies a bit, assuming you have no future data.
select calendar_date, Tim_Tag_YTD = case DATEDIFF(YEAR, calendar_date, GETDATE()) when 0 then 'CYTD' when 1 then 'LYTD' else 'Other' end from
In the case of your logic, you explicitly put future data in "Other", which can also be done like this:
select calendar_date, Tim_Tag_YTD = case when calendar_date > GETDATE() then 'Other' else case DATEDIFF(YEAR, calendar_date, GETDATE()) when 0 then 'CYTD' when 1 then 'LYTD' else 'Other' end end from
source share