Avatar of HKFuey
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

SQL filter for last months data

I have a SQL view with the criteria below, I'm trying to get last months transactions. My criteria works most of the time except in month 1 of the year.

WHERE        (DATEPART(yyyy, dbo.SLPostedCustomerTran.TransactionDate) = DATEPART(yyyy, DATEADD(m, - 1, GETDATE()))) AND (DATEPART(m, dbo.SLPostedCustomerTran.TransactionDate) = DATEPART(m, DATEADD(m, - 1, GETDATE())))

Can anyone help?

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon