You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IF @Yesterday>=@NextMonth --Any Date that equals to or is greater than 1st of next Month return the last date of the previous (Current Reporting) Month.
SELECT @EndDate=CONVERT(VARCHAR,DATEADD(day,-1,@NextMonth),112) --Get the end of the month: Hard Set, don't worry about Weekends.
ELSE
BEGIN
SELECT @EndDate = CASE DATEPART(dw, @Yesterday) --Sunday is 1, Saturday = 7 (Default: United States, Sunday is the first day of the week)
WHEN 1 THEN CONVERT(VARCHAR,DATEADD(day, -2, @Yesterday),112)--Sunday Go back 2 days
WHEN 7 THEN CONVERT(VARCHAR, DATEADD(day, -1, @Yesterday), 112)--Saturday Go Back 1 Day