19
19
, DiffWK = DATEDIFF(WEEK , 0 , @SeedDate)
20
20
, DiffMM = DATEDIFF(MONTH , 0 , @SeedDate)
21
21
, DiffQQ = DATEDIFF(QUARTER, 0 , @SeedDate)
22
- , DiffYY = DATEDIFF(YEAR , 0 , @SeedDate)
22
+ , DiffYY = DATEDIFF(YEAR , 0 , @SeedDate)
23
23
)
24
24
INSERT INTO @Return (Code, [Label], BeginDate, EndDateInclusiveDT, EndDateInclusiveDT2, EndDateExclusive)
25
25
SELECT Code = x .Code
51
51
) x(Code, [Period], BeginDate, EndDate)
52
52
WHERE x .Code = @DateCode OR @DateCode IS NULL
53
53
UNION
54
- -- Handling for P7D and L7D style date codes
55
- -- Supporting only days for now. Months requires a bit more work to calcualte the end of month value.
54
+ -- Handling for P7D and L7D style date codes
55
+ -- Supporting only days for now. Months requires a bit more work to calcualte the end of month value.
56
56
SELECT Code = UPPER (@DateCode)
57
57
, [Label] = CONCAT_WS(' ' , CASE LEFT(@DateCode, 1 ) WHEN ' L' THEN ' Last' WHEN ' P' THEN ' Previous' ELSE NULL END, t.[Value], ' days' )
58
58
, BeginDate = CONVERT (datetime2, x .BeginDate )
@@ -69,7 +69,18 @@ BEGIN;
69
69
) x
70
70
WHERE @DateCode LIKE ' [LP][0-9]D'
71
71
OR @DateCode LIKE ' [LP][0-9][0-9]D'
72
- OR @DateCode LIKE ' [LP][0-9][0-9][0-9]D' ;
72
+ OR @DateCode LIKE ' [LP][0-9][0-9][0-9]D'
73
+
74
+ IF (@DateCode IS NULL ) -- If the DateCode is not provided, then fill in some standard options
75
+ BEGIN ;
76
+ -- Ew, gross, recursion, I know. But, it's the easiest way to include both a common set of options, while still supporting dynamic entries
77
+ INSERT INTO @Return (Code, [Label], BeginDate, EndDateInclusiveDT, EndDateInclusiveDT2, EndDateExclusive)
78
+ SELECT y .Code , y.[Label], y .BeginDate , y .EndDateInclusiveDT , y .EndDateInclusiveDT2 , y .EndDateExclusive
79
+ FROM (VALUES (' L7D' ),(' L14D' ),(' L30D' ),(' L60D' ),(' L90D' )
80
+ ,(' P7D' ),(' P14D' ),(' P30D' ),(' P60D' ),(' P90D' )
81
+ ) x(DateCode)
82
+ CROSS APPLY dbo .uf_DateCalc (@SeedDate, x .DateCode ) y
83
+ END;
73
84
74
85
RETURN;
75
86
END;
0 commit comments