SQL queries for fiscal years and periods in Dynamics GP
Views (5176)
Often when creating reports we’re asked to show the current year vs. last year or select the current fiscal year or period as a date range for values returned. Sometimes dates can be hard-coded, especially when the fiscal year is the calendar year. But some reports can be made more dynamic by using the fiscal periods set up in Dynamics GP. It can also help simply to see what is set up in GP at times, so that you know how to best structure the report. Below are two queries that can help with this.
All fiscal years:
SELECT YEAR1 [Year], FSTFSCDY First_Day, LSTFSCDY Last_Day, NUMOFPER Number_of_Periods, CASE HISTORYR WHEN 0 THEN 'Open Year' WHEN 1 THEN 'Historical Year' END Year_Status FROM SY40101 ORDER BY YEAR1
Fiscal periods for the current year:
SELECT
D.PERIODID Period_Number,
D.PERNAME Period_Name,
D.PERIODDT Starting_Date,
D.PERDENDT Ending_Date,
D.YEAR1 Fiscal_Year
FROM SY40100 D
INNER JOIN
SY40101 H
ON H.YEAR1 = D.YEAR1
WHERE
D.FORIGIN = 1 AND D.PERIODID <> 0
and GETDATE() between H.FSTFSCDY and H.LSTFSCDY
ORDER BY D.PERIODID
You can change the line in blue above if you need to see a different year. Sample results:
Filed under: Dynamics GP, GP Reports code, Sytem/Setup SQL code Tagged: Dynamics GP, GP Reports code, SQL code

This was originally posted here.
*This post is locked for comments