I'm basically running a query like this example:
I'm ending up with the results I want, but I want to narrow the results down to the most recent date (and not show the records corresponding to the previous dates). For example, I'm returning these fields:
So, basically there was an invoice made on 1/1/2007, for serial#'s 42885C and 42066C. On 8/3/2007 there was a rental invoice created for these two serial #'s. Then on 9/3/2007, there was another rental invoice created for these two serial #'s.
In this list of results that has multiple invoices for multiple customers in multiple locations, when there is one original invoice and multiple rental invoices that correspond to the original invoice. How can I show the records that correspond to the most recent rental invoice date? In this case it would be 9-3-2007.
Code:
SELECT RT.serial, Rt.Customer, RT.Invoice, RT.RentalTxnDate, RT.TxnLineID,RT.Location, CD.InvoiceTxnDate
FROM RentalsView as RT
INNER JOIN InvoicesView as CD
ON RT.serial = CD.serial
AND RT.customer = CD.customer
AND RT.RentalTxnDate >= CD.InvoiceTxnDate
GROUP BY
RentalTxnDate, Customer, Invoice, Serial, TxnLineID, Location, InvoiceTxnDate
I'm ending up with the results I want, but I want to narrow the results down to the most recent date (and not show the records corresponding to the previous dates). For example, I'm returning these fields:
Code:
RentalTxnDate, Customer,Invoice,Serial,TxnLineID,Location,InvoiceTxnDate
Data looks something like:
8-3-2007 | Killian | 19209 | 42885C | D4D3-1188518188 | OC | 1-1-2007
8-3-2007 | Killian | 19209 | 42066C | D4D4-1188518188 | OC | 1-1-2007
9-3-2007 | Killian | 22013 | 42885C | DF97-1191364685 | OC | 1-1-2007
9-3-2007 | Killian | 22013 | 42066C | DF98-1191364685 | OC | 1-1-2007
So, basically there was an invoice made on 1/1/2007, for serial#'s 42885C and 42066C. On 8/3/2007 there was a rental invoice created for these two serial #'s. Then on 9/3/2007, there was another rental invoice created for these two serial #'s.
In this list of results that has multiple invoices for multiple customers in multiple locations, when there is one original invoice and multiple rental invoices that correspond to the original invoice. How can I show the records that correspond to the most recent rental invoice date? In this case it would be 9-3-2007.