Hello
I have sql 2008 r2 and first I have to get today's date to calculate the total sales of the month
Example getdate(now) this results on ´2019-09-18´ so I need to get the total sales of the mont (Sep-01 to Sep-18) but all this for the last year so I need a formula to get all the invoices from Sep-01-2019 to Sep-18-2019 to get the total sale of September
Something Like this :
SELECT Sales
FROM SalesTable
WHERE YEAR(InvoiceDate) = YEAR(GETDATE())-1 AND MONTH(InvoiceDate) = MONTH(GETDATE()) AND DAY(InvoiceDate)<=DAY(GETDATE())
Thanks in advance