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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - 谢T

转载:老问题再次发生 “从客户端(userName="<hr />")中检测到有潜在危险的 Request.Form 值” 解决方案 数据绑定 DataTable - 谢T - 博客园 清除SQL注入的语句 分页存储过程3 生活规则 分页存储过程-01(转) html 导出 word (转) - 谢T ado.net 数据阅读器 - 谢T - 博客园 双截棍(程序员版) ado.net 续1 交流学习 yo2 Blog(WordPress) 申请码大放送 初识 ado.net 页面传值 ASP.NET 2.0技术内幕 20080606 第一部分 .net与面向对象 第一章 OO大智慧 开始
分页存储过程-02 (CodeMatic)
谢T · 2009-04-01 · via 博客园 - 谢T

 1 ------------------------------------
 2 --用途:分页存储过程(对有主键的表效率极高)  
 3 --说明:
 4 ------------------------------------
 5 
 6 CREATE PROCEDURE UP_GetRecordByPage
 7     @tblName      varchar(255),       -- 表名
 8     @fldName      varchar(255),       -- 主键字段名
 9     @PageSize     int = 10,           -- 页尺寸
10     @PageIndex    int = 1,            -- 页码
11     @IsReCount    bit = 0,            -- 返回记录总数, 非 0 值则返回
12     @OrderType    bit = 0,            -- 设置排序类型, 非 0 值则降序
13     @strWhere     varchar(1000= ''  -- 查询条件 (注意: 不要加 where)
14 AS
15 
16 declare @strSQL   varchar(6000)       -- 主语句
17 declare @strTmp   varchar(100)        -- 临时变量
18 declare @strOrder varchar(400)        -- 排序类型
19 
20 if @OrderType != 0
21 begin
22     set @strTmp = '<(select min'
23     set @strOrder = ' order by [' + @fldName +'] desc'
24 end
25 else
26 begin
27     set @strTmp = '>(select max'
28     set @strOrder = ' order by [' + @fldName +'] asc'
29 end
30 
31 set @strSQL = 'select top ' + str(@PageSize+ ' * from ['
32     + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
33     + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize+ ' ['
34     + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
35     + @strOrder
36 
37 if @strWhere != ''
38     set @strSQL = 'select top ' + str(@PageSize+ ' * from ['
39         + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
40         + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize+ ' ['
41         + @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
42         + @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
43 
44 if @PageIndex = 1
45 begin
46     set @strTmp =''
47     if @strWhere != ''
48         set @strTmp = ' where ' + @strWhere
49 
50     set @strSQL = 'select top ' + str(@PageSize+ ' * from ['
51         + @tblName + ']' + @strTmp + ' ' + @strOrder
52 end
53 
54 if @IsReCount != 0
55     set @strSQL = 'select count(*) as Total from [' + @tblName + ']'+' where ' + @strWhere
56 
57 exec (@strSQL)
58 
59 GO