Monday, March 12, 2012

Last Function

SQL Server has no Last() and Max() pulls the Max not the last. Is there a way to pull the Last payment amount with the date of that payment, in SQL Server??

tblClients - ClientID (PK)
tblPayments - PaymentID (PK)

Thanks for any help,You can add a timestamp column to the table and then use Max(TimestampCol) to return the last inserted record (which i assume you want to return), e.g.


SELECT
*
FROM
myTable
WHERE
myTable.TimestampCol = (SELECT Max(TimestampCol) FROM myTable)
|||You're going to have to date stamp your transactions.

No comments:

Post a Comment