标签:sql 分页 tor 语句 数据 red tput alter null
USE [web1]
GO
/****** Object: StoredProcedure [dbo].[GetPageList] Script Date: 08/22/2014 15:02:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter PROCEDURE [dbo].[GetPageList]
@TableName varchar(20),
@IdName varchar(10),
@pageSize int,
@pageIndex int,
@rowsCount int output
AS
BEGIN
SET NOCOUNT ON;
--获取总行数
declare @sql1 nvarchar(200)
set @sql1=N‘select @count=count(*) from ‘+@TableName --定义一个有参数的sql语句
exec sp_executesq --系统存储过程,用于执行一个字符串作为sql
@sql1,
N‘@count int out‘,--为sql语句定义参数
@rowsCount out --执行sql语句时提供参数
--获取当前页的数据
declare @sql2 nvarchar(200)
set @sql2=‘select *,ROW_NUMBER() over(order by ‘+@IdName+‘ desc) as id1
from ‘+@TableName
set @sql2=‘select top ‘+ltrim(str(@pageSize))+‘ * from (‘+
@sql2+‘) as t1 where id1>‘+ltrim(str((@pageIndex-1)*@pageSize))
exec(@sql2)
END
标签:sql 分页 tor 语句 数据 red tput alter null
原文地址:https://www.cnblogs.com/jiangyunfeng/p/11134238.html