sql - How do I compare a dayname to a date and get a date to compare with it? -


part of query checks need have if it's monday first working day of month, return date 3 days back, otherwise take is. came piece of code, reason it's not working. suggestions?

requestdate >= case when(datename(dw,day(@st)) 'monday') ,           (((day(@st) = 01)) or ((day(@st) = 02)) or ((day(@st) = 03)))         dateadd(d,-3,@st)          else @st end 

i suggest not using day-of-week names , using day-of-week values instead:

declare @st datetime set @st = '06/01/2015'  select   case     when       datepart( dw, @st ) = 2 ,       datepart( d, @st ) < 4           dateadd( d, -3, @st )     else        @st   end requestdate 

Comments