Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Declare @TheDate DateTime
Set @TheDate = '2007-02-19'
Set DateFirst 7
select Case When DatePart(weekday, @TheDate) = 2
Then @TheDate - 3
Else @TheDate - 1
End As Yesterday
Declare @TheDate DateTime
Set @TheDate = '2007-02-12'
Set DateFirst 7
select Case When DatePart(weekday, @TheDate) = 1 Then @TheDate - 2
When DatePart(weekday, @TheDate) = 2 Then @TheDate - 3
Else @TheDate - 1
End As Yesterday
--test data
declare @datetest table (dt datetime)
insert into @datetest
select '2007-02-18'
union all select '2007-02-19'
union all select '2007-02-20'
union all select '2007-02-21'
union all select '2007-02-22'
union all select '2007-02-23'
union all select '2007-02-24'
--here's the query
select dt, datepart(dw, dt)
, case datepart(dw,dt)
when 2 then dateadd(day, -3, dt)
when 1 then dateadd(day, -2, dt)
else dateadd(day, -1, dt) end as PreBDay
from @datetest