I'm looking to get any data that occurred during the past 3 business days.
If today is a Monday, I want my query to pull for data that happened on Wednesday, Thursday, and Friday of last week.
If it's Tuesday, pull data that occurred on Thursday, Friday, and Monday.
If it's Wednesday, pull for Friday, Monday, Tuesday. Etc.
This is what I have so far in my WHERE statement, but I know it is incorrect.
AND CASE
WHEN DATENAME(DW, GETDATE()) = 'Monday' THEN CAST(PE.SchedDt AS DATE) BETWEEN DATEADD(DAY,-5,CAST(GETDATE()AS DATE)) AND DATEADD(DAY,-3,CAST(GETDATE()AS DATE))
WHEN DATENAME(DW, GETDATE()) = 'Tuesday' THEN CAST(PE.SchedDt AS DATE) BETWEEN DATEADD(DAY,-5,CAST(GETDATE()AS DATE)) AND DATEADD(DAY,-1,CAST(GETDATE()AS DATE))
WHEN DATENAME(DW, GETDATE()) = 'Wednesday' THEN CAST(PE.SchedDt AS DATE) BETWEEN DATEADD(DAY,-5,CAST(GETDATE()AS DATE)) AND DATEADD(DAY,-2,CAST(GETDATE()AS DATE))
ELSE CAST(PE.SchedDt AS DATE) BETWEEN DATEADD(DAY,-3,CAST(GETDATE()AS DATE)) AND DATEADD(DAY,-1,CAST(GETDATE()AS DATE))
END
Any help with this is much appreciated!