Created
October 27, 2014 15:31
-
-
Save benj2240/05f12d2063dc2b6b996e to your computer and use it in GitHub Desktop.
Weekend Dodging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT ProjectedDate = DATEADD( DAY | |
| ,CASE(DATEPART(WEEKDAY, DATEADD(DAY, Margin, BaseDate))) | |
| WHEN 7 THEN -1 -- Go back 1 day from Saturday | |
| WHEN 1 THEN 1 -- Go forward 1 day from Sunday | |
| ELSE 0 -- Weekdays stay as-is | |
| END | |
| ,DATEADD(DAY, Margin, BaseDate) | |
| ) | |
| FROM BaseDates | |
| JOIN ProjectionMargins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT ProjectedDate = DATEADD( DAY | |
| ,Margin + CASE(DATEPART(WEEKDAY, DATEADD(DAY, Margin, BaseDate))) | |
| WHEN 7 THEN -1 -- Go back 1 day from Saturday | |
| WHEN 1 THEN 1 -- Go forward 1 day from Sunday | |
| ELSE 0 -- Weekdays stay as-is | |
| END | |
| ,BaseDate | |
| ) | |
| FROM BaseDates | |
| JOIN ProjectionMargins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment