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.
Author |
Topic |
juicemousezero
Starting Member
10 Posts |
Posted - 2005-12-05 : 11:45:00
|
I'm trying to make an asp.net guestbook, and I'm pretty sure I won’t have any problems when it comes to inserting the new guestbook entry into the DB. But one of the features I'd like to have is that on the GB page, the latest top ten GB entries are always displayed. Still easy enough... but I also want to have links at the bottom of the page that are created dynamically depending on whether or not there are older entries in the GB. If there are, when you click the link I need the next oldest ten entries to be displayed... So pretty much what I need is a stored procedure that selects the top ten rows and also lets me specify the index at which I begin displaying the ten rows (which I'll collect with the request.querystring method). I.e., on the initial load of the page the latest ten entries are displayed, but if the querystring says 10, the stored procedure will start on the tenth row and display the next ten. I did it in MySQL once with this query: SELECT * FROM Guestbook ORDER BY id DESC LIMIT $start, 10But there's no LIMIT keyword in t-sql, and I can’t seem to find anything else that lets me enter my starting index as well as the number of rows I want returned. So I'm trying to write a stored procedure that does this, but I'm just not familiar enough with t-sql syntax to know exactly what to do. I'm thinking I can do this just with a where clause but I'm not sure. This is a rough draft of what I'm trying to do... DECLARE @start int Select top 10 [name], website, comments from Guestbook where id = @start order by id descBut of course that only returns one row... so no good.Sorry if this is unclear at all... this was a lot harder to put into words than I thought it'd be.. :-) but any help would be cool. Thanks guys. |
|
jhermiz
3564 Posts |
Posted - 2005-12-05 : 13:10:33
|
Look up paging in search. Keeping the web experience alive -- [url]http://www.web-impulse.com[/url] |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|