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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 在北京的湖南人

Table变量和临时表区别 C#trim不掉空格的原因 - 在北京的湖南人 - 博客园 vss2005 只获取到文件夹获取不到文件的解决 关于asp.net session机制的疑惑以及猜想 一段关于浏览器兼容的事件定位代码,经过测试! 收集关于scrollTop信息 数据库中null字段在逻辑层的判断的两种办法 - 在北京的湖南人 - 博客园 sql 优化之关于null 和数据类型 js trim函数 复制粘贴都出错,还有什么错不能出的? sql 优化实战 从 35秒到0秒 又从0秒到25秒 asp.net上传时出现的问题:"对路径的访问被拒绝" gridview超链接列带多个参数 访问 IIS 元数据库失败 sql server clr 集成系列之四 创建一个clr的表值函数---实用的Split函数 sql server 2005 clr 集成 之三 关于context connetion sql server clr 集成系列之二 简单的sql 函数 Sql server 2005 Clr集成系列开篇 为什么微软要集成clr 到sql server? return语句写错地方导致数据库表长时间被锁
sql server 2005 新分页存储过程
在北京的湖南人 · 2007-03-27 · via 博客园 - 在北京的湖南人

create   PROCEDURE [dbo].[PagingRecord]
    ( 
    
@PageIndex int,--页号,从0开始
    @PageSize int,--页尺寸
    @OrderField varchar(100),--排序字段及类型(多个条件用逗号分开)如:JobID DESC,Checkintime
    @TableName varchar(100),--表名或视图表 
    @FieldList varchar(2000),--欲选择字段列表      
    @DoCount  AS bit=1-- 0值返回记录总数, 非 0 值则返回记录
    ) 
AS 



DECLARE @SqlQuery varchar(4000)

IF @DoCount<>0--需要返回记录总数
begin
    
DECLARE @SearchSql AS Nvarchar(4000)
    
SET @SearchSql= 'SELECT Count(*) AS Total FROM '+@tablename
    
exec sp_executesql @SearchSql
    
--print @SearchSql 
end


    
SET @SqlQuery='SELECT '+@FieldList+'
    FROM (SELECT row_number() over(ORDER BY 
'+@OrderField+') as rownum, 
            
'+@FieldList+'
          FROM 
'+@TableName+') as temp
    WHERE rownum BETWEEN (
'+cast(@PageIndex as varchar)+'-1)*'+cast(@PageSize as varchar)+'+1 and '+cast(@PageIndex as varchar)+'*'+cast(@PageSize as varchar)+'
    ORDER BY 
'+@OrderField
    
--print @SqlQuery
    SET NOCOUNT ON
    
execute(@SqlQuery)
    
SET NOCOUNT OFF

注意事项:
传入的那个table字符串,你可以后面加上 where 条件拼接起来。
如果需要返回总查询量,最后那个参数 @DoCount 传递 1 进去,不然传递 0 进去。

这个是这篇文章的改编   http://www.cnblogs.com/Randy0528/archive/2007/02/05/640788.html