psdpainter
psdpainter

Reputation: 666

Sql query: alter current year with DATEADD

My current organization's fiscal year isn't equal to the current calendar year, so July 1 is actually month 1 in 2014.

Given the following sql:

SELECT *
FROM (
SELECT F.id, F.account, F.Pd AS Period, F.Actual AS Totals,
    C.PROJ_NAME
    FROM Foo.FinalData F
    INNER JOIN Foo.ProjectCustom C
    ON F.id = C.id
    WHERE F.id LIKE '61000.001.001.%'
    AND F.Account NOT LIKE '%-01'
    AND `F.fy = DATEADD(yy, +1, GetDate())`
) Budget
PIVOT (
    SUM(Totals) FOR Period in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) AS PivotTable;

How could I write the query to understand July 1 is equivalent to the new current year?

Upvotes: 0

Views: 213

Answers (1)

Nenad Zivkovic
Nenad Zivkovic

Reputation: 18559

I am guessing F.fy column is fiscal year you want to compare with year from date? Something like this could do the trick:

AND f.fy = YEAR(DATEADD(MM,6,GETDATE()))

Upvotes: 2

Related Questions