To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-18-2002, 03:30 AM
waimanlam waimanlam is offline
Junior Member
 
Join Date: Oct 2002
Posts: 1
Unhappy TOP x records - what about next x records?

I am trying to implement something a function within SQL server 2000 which allows a user to identify the number of the record returned from a table (it is a bit like record paging). The stored procedure will be using the following syntax:

exec MySPName 'table_name', startRecord, numberofRowsReturn

For example, if startrecord = 1, numberofRowsReturn = 20, the first 20 records in a table will be returned...etc.

I have tried using a combination of 'top x' and 'not exists' but then it does not seem to work.. Anyone has better idea?

Thanks in advance.
Cheers,
Wai-man
Reply With Quote
  #2  
Old 11-15-2002, 12:49 PM
pan pan is offline
Junior Member
 
Join Date: Sep 2002
Posts: 12
Try the following stored procedure:


CREATE PROCEDURE MySP @TABLE VARCHAR(30), @Start INT, @NumOfRecords INT AS
SET NOCOUNT ON
DECLARE @STR VARCHAR(3000)
DECLARE @counter INT
SELECT @counter = @Start
SELECT @STR ='DECLARE curs CURSOR SCROLL FOR SELECT * FROM '+@TABLE
EXEC (@STR)
OPEN curs
WHILE @counter < (@Start + @NumOfRecords) AND @@FETCH_STATUS <> -2
BEGIN
FETCH ABSOLUTE @counter FROM curs
SELECT @counter = @counter + 1
END
CLOSE curs
DEALLOCATE curs
GO
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:55 AM.


DatabaseJournal Recent Articles


 » Searching and Sorting Strings in Oracle

 » Preparing To Upgrade Access Tables to SQL ...

 » Sun Expands MySQL With Closed Source

 » Microsoft Demos New SQL Server Features at...

 » Wipro and Oracle Launch First Joint Innova...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.