分页储存过程
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
USE [Chinavalue]
GO
/****** Object: StoredProcedure [dbo].[pr_GetDataList] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
函数名称: pr_GetDataList
函数功能: 获取指定表的数据
参数说明:
@SelectedFields 选择的字段名
@TableName nvarchar(100) 要查询的表名
@Counts INT 选择的记录数(0为选择全部)
@Condition nvarchar(1000) 查询条件(不加WHERE ,如:AND a=1 AND b=2)
@Order nvarchar(20) 排序(如 AddTime DESC)
创 建 者:
创建时间:
修 改 者:
修改时间:
*/
ALTER proc [dbo].[pr_GetDataList]
(
@SelectedFields nvarchar(500),
@TableName nvarchar(100),
@Counts nvarchar(10),
@Condition nvarchar(1000),
@Order nvarchar(20)
)
AS
declare @strSQL nvarchar(3000) -- 主语句
declare @strTmp nvarchar(1000) -- 临时变量
if(@Counts != 0 AND @Counts != '')
SET @strSQL = 'SELECT TOP ' + @Counts + ' ' + @SelectedFields + ' FROM ' + @TableName + ' WHERE 1=1 ' + @Condition + ' ORDER BY ' + @Order
else
SET @strSQL = 'SELECT ' + @SelectedFields + ' FROM ' + @TableName + ' WHERE 1=1 ' + @Condition + ' ORDER BY ' + @Order
exec(@strSQL)