I have a sql query that shows the year in one column and the month in another. I can show the report as the current year but i need to show it in fiscal form, for example our fiscal yr is from oct-oct so how can I do this in sql? My current query below:
SELECT TOP (15) dbo.timelinedayres_v1_0.fiscalyear,
dbo.timelinedayres_v1_0.fiscalmonth,
SUM(dbo.factqht_v2.baanstandarcost) AS stdcost,
CAST(dbo.timelinedayres_v1_0.fiscalmonth AS VARCHAR) + ' - ' +
CAST(dbo.timelinedayres_v1_0.fiscalyear AS VARCHAR) AS CONCAT
FROM dbo.timelinedayres_v1_0
INNER JOIN dbo.factqht_v2
ON dbo.timelinedayres_v1_0.epoch = dbo.factqht_v2.qhtwfclosedtimekey
INNER JOIN dbo.dimqht_v2
ON dbo.factqht_v2.qhtid = dbo.dimqht_v2.qhtid
LEFT OUTER JOIN dbo.dimqhtmaterials_v2
ON dbo.factqht_v2.materialid = dbo.dimqhtmaterials_v2.materialid
LEFT OUTER JOIN dbo.dimqhtdispositions_v2
ON dbo.factqht_v2.dispositionid =
dbo.dimqhtdispositions_v2.dispositionid
GROUP BY dbo.dimqhtdispositions_v2.TYPE,
dbo.timelinedayres_v1_0.fiscalyear,
dbo.timelinedayres_v1_0.fiscalmonth,
dbo.dimqht_v2.toplevelassembly_majoritemgroupdesc,
CAST(dbo.timelinedayres_v1_0.fiscalmonth AS VARCHAR) + ' - ' +
CAST(dbo.timelinedayres_v1_0.fiscalyear AS VARCHAR)
HAVING ( dbo.dimqhtdispositions_v2.TYPE = N'Scrap' )
AND ( dbo.dimqht_v2.toplevelassembly_majoritemgroupdesc =
'Torquer Motors' )
ORDER BY dbo.timelinedayres_v1_0.fiscalmonth
This is how I do it:
Since we are in november, this will return 2012, if the date is october it will return 2011. You can adjust your offset.
If you’re coming in from just a month/year then you could do something like this: