All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0高级控件之FileUpload控件_[Asp.Net教程]
C#,WinForm中DataGrid列设置
ASP.Net中利用CSS实现多界面两法_[Asp.Net教程]
SQL Server 存储过程的经典分页_[SQL Server教程]
Asp.Net2.0权限树中Checkbox的操作_[Asp.Net教程]
SQL,SERVER中一些对象的名称更改_[SQL,Server教程]
用sql存储过程实现前台标题变色_[SQL Server教程]
Apache伪静态html(URL,Rewrite)设置法_php资料_编程技术
网页播放器实现全屏的方法总结_JavaScript技术_编程技术
弹出窗口window.open()的参数列表_[Html教程]
Reading number is top 10 pictures
漂亮的跳舞妹妹1
Sexy women in 2013--1
Take you to walk into the most true north Korea rural2
Household design of gorgeous series
Take you to walk into the most true north Korea rural4
9.3阅兵全景图2-英雄连队梯队和外国方阵梯队
yy365网站上的美女2
Perfect small Laurie2
Photographed the passion of the clients and prostitutes in the sex trade picture1
NeedWallpaper1
Download software ranking
Call Of Duty2
Kung fu panda - the secret of the teacher
Red cliff
Sora aoi 120 minutes
Boxer vs Yellow2
打鸟视频
Tram sex maniac 2 (H) rar bag11
Unix video tutorial9
C++教程第四版
The Bermuda triangle1
归海一刀 published in(发表于) 2014/2/1 0:10:57 Edit(编辑)
SQL,server,2005的简单分页程序_[SQL,Server教程]

SQL,server,2005的简单分页程序_[SQL,Server教程]

SQL server 2005的简单分页程序_[SQL Server教程]

SQL2005增加了不少新特性,其中NTILE和ROW_NUMER使得我们不再为SQL如何灵活方便的分页伤脑筋了(不必再羡慕Oracle等数据库了)。
  下面就是一个很简单的分页查询语句: DECLARE @rows_per_page AS INTEGER
DECLARE @current_page AS INTEGER
DECLARE @total_pages AS INTEGER


-- 设置每页的行数
SET @rows_per_page = 20
-- 设置要显示的页号(从1开始)
SET @current_page = 2
-- 计算总页数
SELECT @total_pages = COUNT(*) / @rows_per_page
FROM testtable;


-- 列出指定页的内容
WITH t AS
(
SELECT NTILE(@total_pages) OVER(ORDER BY id) AS page_number, *
FROM testtable
)
SELECT * from t
WHERE page_number = @current_page   程序简单到可以不用说明的程度。
  我们可以利用上述简单的语句,变化排序条件和查询表,就可以做出一个很通用的分页查询的存储过程或查询语句了。


  同样的,使用ROW_NUMBER也可以做到分页查询: DECLARE @rows_per_page AS INTEGER
DECLARE @current_page AS INTEGER
DECLARE @start_row_num AS INTEGER


-- 设置每页的行数
SET @rows_per_page = 20
-- 设置要显示的页号(从1开始)
SET @current_page = 2
-- 设置开始行号
SET @start_row_num = (@current_page - 1) * @rows_per_page


WITH t AS
(
SELECT ROW_NUMBER() OVER(ORDER BY id) AS row_number, *
FROM testtable
)
SELECT * from t
WHERE row_number BETWEEN @start_row_num AND @start_row_num + @rows_per_page  似乎更简单的样子。


  至于哪种效率更高,这需要大家实际测试了。


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.