ALTER PROCEDURE [dbo].[gzProc_TablePage]
@tablename varchar(MAX),--表名
@selcolumn varchar(MAX),--查询字段
@where varchar(MAX),--where条件
@sortcolumn varchar(MAX),--排序字段
@pagecount int,--每页记录数
@pageindex int--页号
AS
BEGIN
/***************************************************
-- 功能:分页查询
-- 作者:GarsonZhang
-- 时间:2016年3月21日10:19:07
-- 备注:
-- 测试:
***************************************************/
declare @beginrow int
declare @endrow int
set @beginrow=0
set @endrow=0
set @beginrow=(@pageindex-1)*@pagecount+1
set @[email protected]*@pagecount
declare @sqlstr VARCHAR(MAX)
set @sqlstr=‘with table1 as(select ‘+ @selcolumn +‘,ROW_NUMBER() OVER(ORDER BY ‘+ @sortcolumn+‘ ) AS ROW‘+
‘ FROM ‘[email protected]+‘ WHERE ‘[email protected]+‘) ‘+‘ SELECT ‘[email protected]+‘ FROM TABLE1 WHERE ROW BETWEEN ‘+cast(@beginrow as nvarchar )+‘ and ‘+cast(@endrow as nvarchar)
PRINT @sqlstr
--set @[email protected] +‘ SELECT ‘+ @selcolumn +‘ FROM TABLE1 WHERE ROW BETWEEN ‘+cast(@beginrow as nvarchar )+‘ and ‘+cast(@endrow as nvarchar)
--set @[email protected] +‘ SELECT ‘[email protected]+‘ FROM TABLE1 WHERE ROW BETWEEN ‘+cast(@beginrow as nvarchar )+‘ and ‘+cast(@endrow as nvarchar)
--PRINT @sqlstr
exec(@sqlstr)
END