Hi.I am trying to get the max payment date (the last time the vendor was paid) - the end result of which is that I really only want those vendors whose max payment date is less than 06/30/06 because I will be updating these vendors to be inactive. Please note that the code below is only trying to find these vendors - it is not an update statement yet.My expected results would be:Vend Name VendCode LastPymtDate-------------------------------Vendor A VendA 02/04/03Vendor B VendB 03/17/03Vendor C VendC 04/04/04Vendor D VendD 05/13/05Vendor E VendE 05/14/05Vendor F VendF 06/30/06
My problem is that no matter how I word my query I seem to be getting the vast majority of the payments (100s of 1000s) rather than the 4200 +/- vendors I should be getting.I have spent a good chunk of my day searching google for examples and trying these examples and have failed. My most recent failure is:select distinct PMM_TEST.dbo.VEND_REMIT.NAME AS RemitVendorName, PMM_TEST.dbo.VEND_REMIT.VEND_NO AS RemitCode, PFM_TEST.dbo.PYMT.DOC_DATE AS 'Last Payment Date' from PMM_TEST.dbo.VEND_REMIT join PMM_TEST.dbo.ADDR on PMM_TEST.dbo.VEND_REMIT.ADDR_ID = PMM_TEST.dbo.ADDR.ADDR_ID join PMM_TEST.dbo.VEND_TERMS on PMM_TEST.dbo.VEND_REMIT.VEND_TERMS_ID = PMM_TEST.dbo.VEND_TERMS.VEND_TERMS_ID join PFM_TEST.dbo.PYMT on PFM_TEST.dbo.PYMT.VEND_CODE = PMM_TEST.dbo.VEND_REMIT.VEND_NOwhere PFM_TEST.dbo.PYMT.DOC_DATE IN (select MAX(PFM_TEST.dbo.PYMT.DOC_DATE) FROM PFM_TEST.dbo.PYMT where PFM_TEST.dbo.PYMT.DOC_DATE < '06/30/2006'group by PFM_TEST.dbo.PYMT.DOC_DATE, PMM_TEST.dbo.VEND_REMIT.NAME, PMM_TEST.dbo.VEND_REMIT.VEND_NO, PFM_TEST.dbo.PYMT.DOC_DATE)order by PMM_TEST.dbo.VEND_REMIT.NAME
Any help anyone could provide would be greatly appreciate.Regards,Sherri ReidSLReidForum NewbieRenton, WA USA