i have a query written which executes everday night at 3.00am i want to pull for the whole month. i have a small problem over here, when it goes to next month it takes that particular month but i want the previous month. how can i do that.
eg: everday it generates total purchases for that month. but when it goes on next month first it give me 0 records because there is no purchase orders generated yet for that month. how can i over come this problem.
FROM linkx.dbname.dbo.iqclerk_purchaseorders po
INNER JOIN linkx.dbname.dbo.iqclerk_receiving ir ON ir.purchaseorderid = po.purchaseorderid
INNER JOIN linkx.dbname.dbo.iqclerk_receivingandproducts rp ON ir.receivingid = rp.receivingid
INNER JOIN linkx.dbname.dbo.iqclerk_stores st ON ir.receiverstoreid = st.storeid
INNER JOIN linkx.dbname.dbo.iQclerk_GlobalProducts gp ON rp.globalproductid = gp.globalproductid
WHERE vendorid = '22'
AND LEFT(gp.categorynumber, 6) = '101010'
AND MONTH(ir.datereceived) = month(GETDATE())
AND year(ir.datereceived) = year(GETDATE())