Monday, September 9, 2013

Build Calendar Month VS Fiscal Month

Query
; WITH RunningNumber AS
(
       SELECT x = 1
       UNION ALL
       SELECT x = x + 1
       FROM   RunningNumber
       WHERE  x < 12
)
SELECT
       Calendar      =      x
,      [Fiscal Starting Feb] = (x + 10) % 12 + 1
,      [Fiscal Starting Mar] = (x + 9) % 12 + 1
,      [Fiscal Starting Apr] = (x + 8) % 12 + 1
,      [Fiscal Starting May] = (x + 7) % 12 + 1
,      [Fiscal Starting Jun] = (x + 6) % 12 + 1
,      [Fiscal Starting Jul] = (x + 5) % 12 + 1
,      [Fiscal Starting Aug] = (x + 4) % 12 + 1
,      [Fiscal Starting Sep] = (x + 3) % 12 + 1
,      [Fiscal Starting Oct] = (x + 2) % 12 + 1
,      [Fiscal Starting Nov] = (x + 1) % 12 + 1
,      [Fiscal Starting Dec] = (x) % 12 + 1

FROM   RunningNumber

Desired Output

No comments:

Post a Comment