分页查询的存储过程
2005-01-12 22:21
507 查看
1.id是数字型或有序的字符型
第一页、上一页、下一页都可用
select top n * from 表 where id>=参数值
最后一页
select @m=count(*) from 表
@m=n%@m
select top @m * from 表 into #tmp1 order by id desc
select * from #tmp1 order by id
或者
select * from 表 where id not in (select top x from 表)
2.
create proc GetAuthors
@Author_Last_Name as varchar(100) = null,
@StartRow as int = null,
@StopRow as int = null
AS
---- 建立有标识符列的table变量
declare @t_table table
(
[rownum] [int] IDENTITY (1, 1) Primary key NOT NULL ,
[Author_Last_Name] [varchar] (40) ,
[Author_First_Name] [varchar] (20) ,
[phone] [char] (12) ,
[address] [varchar] (40) ,
[city] [varchar] (20) ,
[state] [char] (2) ,
[zip] [char] (5)
)
---- 在返回指定的@StopRow行数之后停止处理查询
Set RowCount @StopRow
---- 插入到table变量中
insert @t_table
(
[Author_Last_Name],[Author_First_Name],[phone],[address],[city],[state],[zip]
)
SELECT [Author_Last_Name],[Author_First_Name],[phone],[address],[city],[state],[zip]
FROM authors
WHERE Author_Last_Name like '%' + @Author_Last_Name + '%'
ORDER BY Author_Last_Name
---- 返回到正确的结果
SELECT * FROM @t_table WHERE rownum >= @StartRow
ORDER BY rownum
GO
第一页、上一页、下一页都可用
select top n * from 表 where id>=参数值
最后一页
select @m=count(*) from 表
@m=n%@m
select top @m * from 表 into #tmp1 order by id desc
select * from #tmp1 order by id
或者
select * from 表 where id not in (select top x from 表)
2.
create proc GetAuthors
@Author_Last_Name as varchar(100) = null,
@StartRow as int = null,
@StopRow as int = null
AS
---- 建立有标识符列的table变量
declare @t_table table
(
[rownum] [int] IDENTITY (1, 1) Primary key NOT NULL ,
[Author_Last_Name] [varchar] (40) ,
[Author_First_Name] [varchar] (20) ,
[phone] [char] (12) ,
[address] [varchar] (40) ,
[city] [varchar] (20) ,
[state] [char] (2) ,
[zip] [char] (5)
)
---- 在返回指定的@StopRow行数之后停止处理查询
Set RowCount @StopRow
---- 插入到table变量中
insert @t_table
(
[Author_Last_Name],[Author_First_Name],[phone],[address],[city],[state],[zip]
)
SELECT [Author_Last_Name],[Author_First_Name],[phone],[address],[city],[state],[zip]
FROM authors
WHERE Author_Last_Name like '%' + @Author_Last_Name + '%'
ORDER BY Author_Last_Name
---- 返回到正确的结果
SELECT * FROM @t_table WHERE rownum >= @StartRow
ORDER BY rownum
GO
相关文章推荐
- Oracle分页查询的一个存储过程:
- 高效通用分页存储过程 多表查询
- SQL Server 存储过程进行分页查询
- SQL Server 2005中利用临时表和@@RowCount提高分页查询存储过程性能
- 通用分页显示查询存储过程
- 客户端如何通过咏南中间件调用存储过程和数据分页查询和文件传输的演示
- 三种SQL分页查询的存储过程代码
- SQL分页查询存储过程代码分享
- SQL分页存储过程和C#中linq分页查询方法
- SQL Server 分页查询通用存储过程
- sql 存储过程分页查询
- MYSQL中存储过程中写入分页查询----深坑
- 通用的可带查询条件的SQL语句的分页存储过程
- SQL之通用查询分页存储过程
- 分页带查询的存储过程示例
- SQLServer分页查询存储过程
- 利用存储过程实现分页 ,并且多条件查询
- 分页存储过程,可将查询条件作为参数传递的分页查询存储过程
- 通用的可带查询条件的SQL语句的分页存储过程(2)