![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi everyone, first im sorry because i dont know how to explain my issue so i have to put a fragment of my code which is written in php and mysql, my goal is transfer this querys to sybase, hope im not disturbing and somebody can help me: $pageNo = $json->{'pageInfo'}->{'pageNum'}; $pageSize = 10; $sql = "select count(*) as cnt from orders"; $handle = mysql_query($sql); $row = mysql_fetch_object($handle); $totalRec = $row->cnt; //make sure pageNo is inbound if($pageNo<1||$pageNo>ceil(($totalRec/$pageSize))){ * $pageNo = 1; } //page index starts with 1 instead of 0 $sql = "select * from orders limit " . ($pageNo - 1)*$pageSize . ", " . $pageSize; This last query is the problem, as you can see this allows me to paging the results increasing the $pageNo so i can ask for page 1 with 10 results, then page 2 with the next 10 and so on. How can i make this with T-SQL? Thanks in advanced. |
#3
| |||
| |||
|
|
On Feb 18, 11:02*am, Jorge Reyes <jorg_re... (AT) hotmail (DOT) com> wrote: Hi everyone, first im sorry because i dont know how to explain my issue so i have to put a fragment of my code which is written in php and mysql, my goal is transfer this querys to sybase, hope im not disturbing and somebody can help me: $pageNo = $json->{'pageInfo'}->{'pageNum'}; $pageSize = 10; $sql = "select count(*) as cnt from orders"; $handle = mysql_query($sql); $row = mysql_fetch_object($handle); $totalRec = $row->cnt; //make sure pageNo is inbound if($pageNo<1||$pageNo>ceil(($totalRec/$pageSize))){ * $pageNo = 1; } //page index starts with 1 instead of 0 $sql = "select * from orders limit " . ($pageNo - 1)*$pageSize . ", " . $pageSize; This last query is the problem, as you can see this allows me to paging the results increasing the $pageNo so i can ask for page 1 with 10 results, then page 2 with the next 10 and so on. How can i make this with T-SQL? Thanks in advanced. Unfortunately, you aren't clear about *which* Sybase database product you are going to be using, and it does make a difference. *There are four: *Adaptive Server Enterprise (ASE), Adaptive Server Anywhere (ASA), Sybase IQ (IQ), and Advantage Database Server. However, in general (and perhaps assuming ASE, which is what I'm most familiar with) One method is to select the results into a temp table adding a rownumber field, you can then "select ... from temptable where rownum between ((pageno -1) * 10) + 1 * *and (pageno * 10) " More details athttp://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12 If using ASE 15.x, you might also consider using a scrollable cursor to accommodate paging backwards and forwards through the result set. http://infocenter.sybase.com/help/to....ase_15.0.sqlu... |
![]() |
| Thread Tools | |
| Display Modes | |
| |