惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
G
GRAHAM CLULEY
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
Cyberwarzone
Cyberwarzone
V
V2EX
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Scott Helme
Scott Helme
A
Arctic Wolf
美团技术团队
S
Schneier on Security
P
Proofpoint News Feed
G
Google Developers Blog
The Hacker News
The Hacker News
S
Securelist
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
T
The Exploit Database - CXSecurity.com
量子位
T
Threatpost
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
B
Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
J
Java Code Geeks
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
Cloudbric
Cloudbric

博客园 - wucf2004

教你一招 - Misc类型插件的妙用(附带插件源码) 如何在nopcommerce3.3注册页面添加密码强度检查仪? nopcommerce之权限模块 nopcommerce3.3简洁版 nopcommerce里面的@Html.Widget("home_page_top") 是什么? 教你一招 - 如何给nopcommerce增加一个类似admin的area 教你一招 - 如何给nopcommerce做一套自己的主题 nopcommerce之移动版简介 网银在线插件 For Nopcommerce V2.6 支付宝插件 For Nopcommerce V2.6 教你一招 - 如何给nopcommerce增加新闻类别模块 教你一招 - 如何使用中文包 教你一招 - 如何使用nopcommerce主题(v2.5) 教你一招 - 如何安装nopcommerce2.5 PropertyInfo PageLoad 事件执行两次 js点击显示全部内容(用于内容比较长时) - wucf2004 - 博客园 asp.net解决中文乱码问题 - wucf2004 - 博客园 asp.net根据生日计算年龄(具体到年月天)
又一个不错的sql分页存储过程,支持排序、搜索
wucf2004 · 2008-11-14 · via 博客园 - wucf2004

CREATE PROCEDURE  sp_GetRecordByPageOrder

@tblName varchar(255)='wdf1', -- 表名

@fldName varchar(1000) = '*', -- 需要返回的列

@OrderfldName varchar(255)='userid', -- 排序的字段名

@PageSize int = 10, -- 页尺寸

@PageIndex int = 1, -- 页码

@IsReCount bit = 0, -- 返回记录总数, 非 0 值则返回

@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序

@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)

AS

declare @strSQL varchar(5000) -- 主语句

declare @strTmp varchar(110) -- 临时变量

declare @strOrder varchar(400) -- 排序类型

if @IsReCount != 0

begin

if @strWhere !=''

set @strSQL = 'select count(*) as Total from [' + @tblName + '] where '+@strWhere

else

set @strSQL = 'select count(*) as Total from [' + @tblName + ']'

end

--以上代码的意思是如果@IsReCount传递过来的不是0,就执行总数统计。以下的所有代码都是@IsReCount为0的情况

else

begin

if @OrderType != 0

begin

set @strTmp = '<(select min'

set @strOrder = ' order by [' + @OrderfldName +'] desc'

--如果@OrderType不是0,就执行降序,这句很重要!

end

else

begin

set @strTmp = '>(select max'

set @strOrder = ' order by [' + @OrderfldName +'] asc'

end

if @PageIndex = 1

begin

if @strWhere != ''

set @strSQL = 'select top ' + str(@PageSize) +' '+@fldName+ ' from [' + @tblName + '] where ' + @strWhere + ' ' + @strOrder

else

set @strSQL = 'select top ' + str(@PageSize) +' '+@fldName+ ' from ['+ @tblName + '] '+ @strOrder

--如果是第一页就执行以上代码,这样会加快执行速度

end

else

begin

--以下代码赋予了@strSQL以真正执行的SQL代码

set @strSQL = 'select top ' + str(@PageSize) +' '+@fldName+ ' from ['

+ @tblName + '] where [' + @OrderfldName + ']' + @strTmp + '(['+ @OrderfldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @OrderfldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder

if @strWhere != ''

set @strSQL = 'select top ' + str(@PageSize) +' '+@fldName+ ' from ['

+ @tblName + '] where [' + @OrderfldName + ']' + @strTmp + '(['

+ @OrderfldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['

+ @OrderfldName + '] from [' + @tblName + '] where ' + @strWhere + ' '

+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder

end

end

exec (@strSQL)
GO