How can I do paging in Sybase without making temp table? (oracle rownum issue)
Question
In Oracle, usually query like this for paging.
SELECT * FROM (SELECT *, rownum rid FROM TABLEA WHERE rownum <= #pageend#)
WHERE rid > #pagestart#
However, there is no "rownum" function in Sybase DBMS.
How can I do that query exactlly same in Sybase?
I found some ways.
use "rowcount"
set rowcount 10
select * from TABLEA
use identity (make temp table)
SELECT *, ROWNUM=IDENTITY(8) INTO #TEMP FROM TABLEA
SELECT * FROM #TEMP WHERE ROWNUM < #pageend# AND ROWNUM >= #pagestart#
DROP TABLE #TEMP
these are not what I want.
rowcount is set at the session level and i don't want make temp table.
Solution
If you have a unique id column on your table you could use SELECT TOP n
SELECT TOP 10 *
FROM tableA
WHERE id BETWEEN @start AND @end
OTHER TIPS
This will give you all the ids so you can use them in a select like "select * where id_column in (ids from query below)
"
select top 10 id_column from trade
where @whereClause
and id_column > 0 //keep replacing this with the max id from the result set
order by id_column
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow