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 rewrite Case statement in Group By
Expect Scripts and Crontab
dBASE III Plus .dbt file
Problem with MS Excel 03 list sycnchronisation with Sharepoint List
installing radmin on a users computer
Excel 2007 - Conditional formatting Contingent on an Adjacent Cell
Trouble Using BMP As Wallpaper
Outgoing mail server
Windows 2003 A.D. integrated DNS - nslookup timeout errors
How To Force A Download Prompt For A Text File On The Web