SqlServer 存储过程分页
适用于2005以上版本
create procedure [dbo].[SP_GetPageList]
(
@columns nvarchar(max), --查询字段
@tablename nvarchar(max), --表名\视图
@orderby nvarchar(max), --排序字段
@swhere nvarchar(max), --查询条件
@pagesize int, --每页条数
@pageindex int, --页的索引
@rowCount int output --总记录数
)
as --获取总记录数
declare @sqlcount Nvarchar(max)
set @sqlcount=N'select @rowCount=count(*) from '+@tablename+' '+@swhere
exec sp_executesql @sqlcount, N'@rowCount int out', @rowCount out --计算页数
declare @pagecout int
if @rowCount%@pagesize>0
set @pagecout=(@rowCount/@pagesize)+1
else
set @pagecout=(@rowCount/@pagesize) --计算起始索引
declare @begin nvarchar(30)
declare @end nvarchar(30) if @pageindex<1
set @pageindex=1 if @pageindex>@pagecout
set @pageindex=@pagecout
set @begin=convert(nvarchar(30), (@pagesize*(@pageindex-1))+1)
set @end=CONVERT(nvarchar(30), @pagesize*@pageindex) --查询结果
declare @sqlre nvarchar(max)
declare @top int
set @top=@pageindex*@pagesize
set @sqlre=N'select top '+Cast(@top as varchar)+' ROW_NUMBER() over('+@orderby+') as rownum, '+@columns+' from '+@tablename+' '+@swhere exec('select '+@columns+' from ('+@sqlre+') a where a.rownum between '+@begin+' and '+@end+' '+@orderby)
SqlServer 存储过程分页的更多相关文章
- sqlserver 存储过程分页管理
-- =============================================-- Author: <Author:刘畅>-- Create date: <Cre ...
- sqlserver 存储过程 分页搜索查询
具体调用实例见代码最后一行注释区域 --if exists(select * from sysobjects where id = object_id(N'page_search') and type ...
- sqlserver存储过程分页记录
USE [HK_ERP]GO/****** Object: StoredProcedure [dbo].[GetPageBillsByShopID] Script Date: 2018/10/30 1 ...
- sqlserver存储过程分页
create procedure [dbo].[SqlPager]@sqlstr nvarchar(4000), --查询字符串@currentpage int, --第N页@pagesize in ...
- SqlServer存储过程应用二:分页查询数据并动态拼接where条件
前言 开发中查询功能是贯穿全文的,我们来盘一盘使用存储过程分页查询,并且支持动态拼接where条件. 划重点:支持动态拼接where条件 对存储过程的使用有疑问的同学去[SqlServer存储过程的创 ...
- MS SQLSERVER通用存储过程分页
最近在面试的时候,遇到个奇葩的秃顶老头面试官. 问:写过存储过程分页吗? 答:没写过,但是我知道分页存储的原理,我自己也写过,只是在工作中没写过. 问:那你这么多年工作中就没写过吗? 答:的确没写过, ...
- SQL存储过程分页(通用的拼接SQL语句思路实现)
多表通用的SQL存储过程分页 案例一: USE [Community] GO /****** Object: StoredProcedure [dbo].[Common_PageList] Scrip ...
- Sqlserver数据库分页查询
Sqlserver数据库分页查询一直是Sqlserver的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页查询 ...
- 【原创】10万条数据采用存储过程分页实现(Mvc+Dapper+存储过程)
有时候大数据量进行查询操作的时候,查询速度很大强度上可以影响用户体验,因此自己简单写了一个demo,简单总结记录一下: 技术:Mvc4+Dapper+Dapper扩展+Sqlserver 目前主要实现 ...
随机推荐
- Eratosthenes筛选法求解质数
问题说明: 除了自身之外,无法被其它整数整除的数称之为质数,要求质数很简单,但如何快速的求出质数则一直是程式设计人员与数学家努力的课题, 在这边介绍一个着名的 Eratosthenes求质数方法. 解 ...
- c#中 ==与equals有什么区别【转】
转至http://www.zybang.com/question/2263895f201ffec6c68b6c304ac4cd61.html 对于值类型.引用类型来说比较过程怎样的?using Sys ...
- python时间处理函数
所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.n ...
- Spring事务注解@Transactional回滚问题
Spring配置文件,声明事务时,如果rollback-for属性没有指定异常或者默认不写:经测试事务只回滚运行时异常(RuntimeException)和错误(Error). <!-- 配置事 ...
- Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
- 织梦系统中出现DedeTag Engine Create File False提示原因及解决方法
今天更新网站时dedecms系统时,遇到一个问题:DedeTag Engine Create File False 出现这样的提示. 其实这也不算是什么错误,我个人觉得最重要的一点就是根目录下没有给 ...
- Codeforces 733C:Epidemic in Monstropolis(暴力贪心)
http://codeforces.com/problemset/problem/733/C 题意:给出一个序列的怪兽体积 ai,怪兽只能吃相邻的怪兽,并且只有体积严格大于相邻的怪兽才能吃,吃完之后, ...
- easyui常现错误
1.easyui-tabs:当data-options的属性设置为true时,其tab内部的内容显示不出来. 2.设置easyui-panel的title格式及字体大小无效 解决方法:在设置title ...
- pgadmin(IDE)工具连接postgres数据库
1. 下载软件 软件地址:http://www.pgadmin.org/download/pgagent.php 2.安装软件 安装过程:略 打开软件64位会出现 “无 ...
- python :列表 字典 集合 类 ----局部变量可以改全局变量
#列表 字典 集合 类 ----局部变量可以改全局变量,除了整数和字符串 names=["alex","jack","luck"] def ...