romeiovasu
asked on
sql 2005 date query
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.
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.
SELECT st.storeid,
st.storename,
gp.description,
rp.quantity,
rp.unitcost
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())
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you are welcome!
ASKER