MAB (fkdfjdierkjflafdafa@yahoo.com) writes:
> Thanks! this works. However its too slow to run on the actual table with
> thousands of rows but i've managed to eliminate most of the rows by
> creating a temporary table and then I run this query on the temporary
> table.
You might need to review your indexes. It is difficult to test
performance on the small sample, but I would try somthing like:
CREATE CLUSTERED INDEX payments_index ON
payments(customerid, date DESC, paymentid DESC)
--
Erland Sommarskog, SQL Server MVP,
sommar@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp