CREATE PROCEDURE GoalerPageSp
@IntPageSize int,
@IntCurrPage int,
@strFields nvarchar(2000),
@strTable varchar(200),
@strWhere varchar(800),
@strOrderType varchar(200),
@strKeyField varchar(50)
AS
SET NOCOUNT ON
DECLARE @tmpSQL nvarchar(4000)--存放动态SQL语句
DECLARE @tmpWhere varchar(800)
DECLARE @tmpAndWhere varchar(800)--用于第N(>1)页上边的查询条件
DECLARE @tmpOrder varchar(200)
DECLARE @tmpD_X varchar(2)
DECLARE @tmpMin_MAX varchar(3)
--设置条件--
IF @strWhere IS NULL OR RTRIM(@strWhere)=''
BEGIN --没有查询条件
SET @tmpWhere=''
SET @tmpAndWhere=''
END
ELSE
BEGIN --有查询条件
SET @tmpWhere=' WHERE '+@strWhere
SET @tmpAndWhere=' AND '+@strWhere
END
--设置排序--
IF @strOrderType != 0
BEGIN--倒序
SET @tmpD_X = '<'
SET @tmpMin_MAX = 'MIN'
SET @tmpOrder=' ORDER BY ' +@strKeyField+ ' DESC'
END
ELSE
BEGIN
SET @tmpD_X = '>'
SET @tmpMin_MAX = 'MAX'
SET @tmpOrder=' ORDER BY ' +@strKeyField+ ' ASC'
END
--SQL查询--
IF @IntCurrPage=1
Set @tmpSQL='SELECT TOP '+CAST(@IntPageSize AS VARCHAR)+' '+@strFields+' FROM '+@strTable+' '+@tmpWhere+' '+@tmpOrder
ELSE
SET @tmpSQL='SELECT TOP '+CAST(@IntPageSize AS VARCHAR)+' '+@strFields+' FROM '+@strTable+' WHERE ('+@strKeyField+' '+@tmpD_X+' (SELECT '+@tmpMin_MAX+'('+@strKeyField+') FROM (SELECT TOP '+CAST(@IntPageSize*(@IntCurrPage-1) AS VARCHAR)+' '+@strKeyField+' FROM '+@strTable+' '+@tmpWhere+' '+@tmpOrder+') AS T))'+@tmpAndWhere+' '+@tmpOrder
@IntPageSize int,
@IntCurrPage int,
@strFields nvarchar(2000),
@strTable varchar(200),
@strWhere varchar(800),
@strOrderType varchar(200),
@strKeyField varchar(50)
AS
SET NOCOUNT ON
DECLARE @tmpSQL nvarchar(4000)--存放动态SQL语句
DECLARE @tmpWhere varchar(800)
DECLARE @tmpAndWhere varchar(800)--用于第N(>1)页上边的查询条件
DECLARE @tmpOrder varchar(200)
DECLARE @tmpD_X varchar(2)
DECLARE @tmpMin_MAX varchar(3)
--设置条件--
IF @strWhere IS NULL OR RTRIM(@strWhere)=''
BEGIN --没有查询条件
SET @tmpWhere=''
SET @tmpAndWhere=''
END
ELSE
BEGIN --有查询条件
SET @tmpWhere=' WHERE '+@strWhere
SET @tmpAndWhere=' AND '+@strWhere
END
--设置排序--
IF @strOrderType != 0
BEGIN--倒序
SET @tmpD_X = '<'
SET @tmpMin_MAX = 'MIN'
SET @tmpOrder=' ORDER BY ' +@strKeyField+ ' DESC'
END
ELSE
BEGIN
SET @tmpD_X = '>'
SET @tmpMin_MAX = 'MAX'
SET @tmpOrder=' ORDER BY ' +@strKeyField+ ' ASC'
END
--SQL查询--
IF @IntCurrPage=1
Set @tmpSQL='SELECT TOP '+CAST(@IntPageSize AS VARCHAR)+' '+@strFields+' FROM '+@strTable+' '+@tmpWhere+' '+@tmpOrder
ELSE
SET @tmpSQL='SELECT TOP '+CAST(@IntPageSize AS VARCHAR)+' '+@strFields+' FROM '+@strTable+' WHERE ('+@strKeyField+' '+@tmpD_X+' (SELECT '+@tmpMin_MAX+'('+@strKeyField+') FROM (SELECT TOP '+CAST(@IntPageSize*(@IntCurrPage-1) AS VARCHAR)+' '+@strKeyField+' FROM '+@strTable+' '+@tmpWhere+' '+@tmpOrder+') AS T))'+@tmpAndWhere+' '+@tmpOrder
内容版权声明:除非注明,否则皆为本站原创文章。