Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure

Author  Topic 

gperque
Starting Member

7 Posts

Posted - 2007-09-12 : 12:06:12
Hi All,

I would like to retrieve the last 5 records entered in a table. How would I construct the stored procedure to do this? I familar with ordering the results in descending order, but I would only like to see the last 5 records entered.

Thanks in advance,
Glenn

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-12 : 12:11:23
SELET TOP 5 * FROM Table ORDER BY AddDT DESC?

We would need DDL and sample data to give you a concrete solution



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-12 : 14:22:20
"the last 5 records entered in a table"

SQL has no concept of the order in which data is added, so you would need a "Date Added" column, or maybe an incrementing identity, or something similar, in order to be able to "Order By" in the sequence you want - as Brett has described

Kristen
Go to Top of Page

gperque
Starting Member

7 Posts

Posted - 2007-09-20 : 15:12:06
Thanks all, I do have a date column and when I retrieved the "TOP 5", it received the data I required.
Go to Top of Page
   

- Advertisement -