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
Shopping Cart with inventory & Paypal Gateway
Ghost workstation with RAID Controller
Hh.exe ?
outlook.pst file disappears, cannot be restored via backup
Vista drivers for HP BJ1100
Why does my email show
[email protected]
<wbr />k instead of my name@ from a form mail script?
how to get datetime format yyyy-mm-dd hh:mi:ss.mmm in EXcel cells while copying from management studio result set?
How to export or extract Outlook calendar to Excel?
does xp media center have a msconfig utility
can not join XP-Pro PC's to domain