use Leo
go

alter function dbo.fn_GetHoliday (@date date)
  returns varchar(50)
as
begin
  declare @s varchar(50)

  select @s =
    case
      when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-01-01') = @date
        then 'New Year'
      when dbo.fn_ShiftHolidayToWorkday(cast(yr + 1 as varchar) + '-01-01') = @date
        then 'New Year'
      when mn = 1 and DayOfMonth between 15 and 21 and DayName = 'Monday'
        then 'Martin Luther King Jr Day'
      when mn = 2 and DayOfMonth between 15 and 21 and DayName = 'Monday'
        then 'Presidents'' Day'
      when mn = 5 and DayOfMonth >= 25 and DayName = 'Monday'
        then 'Memorial Day'
      when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-06-19') = @date
        then 'Juneteenth'
      when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-07-04') = @date
        then 'Independence Day'
      when mn = 9 and DayOfMonth <= 7 and DayName = 'Monday'
        then 'Labor Day'
      when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-11-11') = @date
        then 'Veteran''s Day'
      when mn = 10 and DayOfMonth between 8 and 14 and DayName = 'Monday'
        then 'Columbus Day'
      when mn = 11 and DayOfMonth between 22 and 28 and DayName = 'Thursday'
        then 'Thanksgiving Day'
      --when mn = 11 and DayOfMonth between 23 and 29 and DayName = 'Friday'
      --  then 'Day After Thanksgiving'
      when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-12-25') = @date
        then 'Christmas Day'
      --when dbo.fn_ShiftHolidayToWorkday(cast(yr as varchar) + '-12-31') = @date
      --  then 'New Years Eve'
      else null
    end
  from (
    select
      yr = year(@date),
      mn = month(@date),
      DayOfMonth = day(@date),
      DayName = datename(weekday,@date)
  ) c

  return @s
end
go
