We help IT Professionals succeed at work.

Get Last N in sql server 2012 web

Bob Schneider
on
I want to allow a web user to determine the number of rows to retrieve from a database beginning with most recent record and go in descending order.  Here is what I am trying (but it is not working):

sql = "SELECT LAST " & iNumToShow & " Bib, PartName, Age, Gender, City, St, Race FROM AnnouncerReads WHERE EventID = " & lEventID
sql = sql & " ORDER By AnnouncerReadsID DESC"

Any help would be much appreciated.
Comment
Watch Question

Database and Application Developer
Commented:
sql = "SELECT Top [" & iNumToShow & "] Bib, PartName, Age, Gender, City, St, Race FROM AnnouncerReads WHERE EventID = " & lEventID
sql = sql & " ORDER By AnnouncerReadsID DESC"

DESC will turn Top to Last
Bob SchneiderCo-Owner

Author

Commented:
Thank you very much!