在SQL Server 2008中,可以使用ROW_NUMBER函数实现分页功能。以下是一个示例查询,演示如何使用ROW_NUMBER函数进行分页:
```sql
SELECT * FROM (
SELECT
column1,
column2,
ROW_NUMBER() OVER (ORDER BY column1) AS RowNumber
FROM
your_table
) AS SubQuery
WHERE
RowNumber BETWEEN @startRowIndex AND @endRowIndex
在上述查询中,your_table是要查询的表名,column1是用于排序的列名。@startRowIndex和@endRowIndex是传入的参数,用于指定要返回的行范围。
ROW_NUMBER()函数将返回一个递增的整数,表示每一行的行号。使用OVER子句来指定排序的列和顺序。在子查询中,将结果作为子查询,并使用WHERE子句过滤行号,以返回指定行范围内的结果。
请注意,column1是用于排序的列,可以根据实际需求修改为其他列。
```sql
@pageSize=2;
@pageIndex=3;
5=(@pageIndex - 1 ) * @pageSize +1;
6= @pageIndex * @pageSize;
SELECT * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY cdate ASC) AS 'RowNumber', * FROM tb_push_order_log where 1=1
) AS tb_push_order_log
WHERE RowNumber BETWEEN 5 AND 6;
select * from (
SELECT
ROW_NUMBER () OVER (ORDER BY a.oper_date DESC) AS RowNumber,
a.item_no ItemNo,
b.item_subno ItemSubno,
item_name ItemName,
stock_qty StockQty
FROM
t_im_branch_stock a
INNER JOIN t_bd_item_info b ON a.item_no = b.item_no
where a.branch_no = '000001'
)a where RowNumber between 1 and 100