Wednesday, June 10, 2009

Return most recent record from a table

SQL syntax - once you see this, it's sooooo obvious!

select top 1 *
from [data table]
where date <= @date

order by date desc

you can remove the where statement if you just want the latest date, if for example you're looking at the sales order backlog and your dates are in the future.

No comments:

Post a Comment