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
Ruby On Rails, Joins? - - - Returning in XML
Windows XP serial ports configuration
bypass login screen on intranet app LDAP authentication VB.Net
wav to mp3
Merge to SQL Server Data Files
(ajaxobject).readyState at zero?
How to connect to database using Vbscript?
Synchronize table structures accords schemas
Can't resize a spredsheet window.
Flash reusing frames throughout timeline