0
votes

I need to write a report to show transaction qty from previous months.

I have the following which works fine until the current month is January

SELECT 'Previous1' as Period, TrnYear,TrnMonth, PartCategory, StockCode, Description, Qty, DrawOfficeNum, WarehouseToUse, JobClassification
FROM     vwUsagePurchPress_1YearHistory
WHERE  (TrnYear = DATEPART(Year, GETDATE())) AND (TrnMonth = DATEPART(Month, GETDATE())-1)

How do I get it to read December from previous year if current month = January

1

1 Answers

0
votes

Your code looks like SQL Server. I would suggest:

 where datediff(month, datefromparts(TrnYear, TrnMonth, 1), getdate) = 1