When a Report is run on a Monday it needs to set the default date to Friday ? Also 4 other conditions looking at the requirments. How to do this in an sql statement is the question.
So in pseudo code,
If today's date is Monday then set default date to Friday with full date format.
If today's date is Saturday then set default date to Friday with full date format.
If today's date is Sunday then set default date to Friday with full date format.
If any other day , then set default date to previous working day .
So need one sql statement maybe with a case statement .
Now I found these statements which give day of week so now need to do next part which may be a case statement or maybe a function ? This is the part I need assistance pl.
select datename(dw,getdate()) --Monday
select datepart(dw,getdate()) -- 1
SET DATEFIRST 1;
DECLARE @day DATE = SYSDATETIME();
SELECT @day = DATEADD
(
DAY,
CASE
WHEN DATEPART(WEEKDAY, @day) IN (1,2)
THEN -(DATEPART(WEEKDAY, @day)+1)
ELSE -1
END,
@day);
SELECT @day;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With