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
How to restore linux pc from .gho file?
I cannot delete two orphaned mailboxes
server 2003 port 3389 not listening after applying SP2
Continual Trojans, Denial of Service, Unauthorized Access on standalone XP Home SP2.
Reminder malfunction
Windows Picture & Fax Viewer stops working
Is there an action script to take me to the end of a swf rather than close it?
EmailAddressPolicy based on Organizational Units
Email Attachments
Change share permissions on many folders with RMTSHARE