Microsoft
Software
Hardware
Network
Question : Retrieving n rows from sybase database - pagination
My problem is:
I have to fetch records from the sybase in a page wise manner,like for first page i have to display 10 records and in the second page 10-20 records etc..
but my main preoblem is in that table 3 Bilion records are there ,but at worst condition my select query fetches 1 Milion records.to execute this query it is taking a lot of time..
is there any way to fetch the records from query specifying the startpoint and endpoint.like
select records from 10 to 20
select records from 30 to 40
select records from 40 to 50 etc..
to fetch only 10 records always Query will take less time to execute.
Answer : Retrieving n rows from sybase database - pagination
Try this
DECLARE tst_cur CURSOR FOR SELECT a, b, c FROM
,
WHERE cond1, cond2
FOR READ ONLY
GO
DECLARE @var1
,
@var2
,
@var3
,
@numrows integer, --- no of rows to fetch
@fetched integer -- running counter
SELECT @fetched=0, @numrows =
OPEN tst_cur
SET CURSOR ROWS
FOR tst_cur
FETCH tst_cur
SET CURSOR ROWS 1 FOR tst_cur
FETCH tst_cur INTO @var1, @var2, @var3
WHILE (@@sqlstatus = 0 AND @fetched <= @numrows)
BEGIN
SELECT @fetched = @fetched +1
SELECT @var1, @var2, @var3 -- you can insert this in a temp table too (if you want)
FETCH tst_cur INTO @var1, @var2, @var3
END
GO
CLOSE tst_cur
DEALLOCATE tst_cur
GO
However be aware that the query would still take the time of retrieval of
+
rows.
But till ASE 15 comes with scrollable cursors...we don't have a simple way of doing this thing.
HTH,
Cheers,
Rij
Random Solutions
can sql server 2000 send sms to mobile (cell) phones
How to run a batch file on a schedule no matter who is logged in.
Help with exporting data using BCP
IE7 search default with Group Policy Management
Access - Pop up form to add ndew customer
Tapeware Backup with MS Exchange Server Objects Busy
Bash script to move and rename files based on a file name
Update query syntax
Set MovieClip Z-Index
illustrator problem " Acrobat PDF Fils Format is having difficulties. The File is damaged and could not be repaired."