declare@strSQLvarchar(5000)--主语句
declare@strTmpvarchar(110)--一时变量
declare@strOrdervarchar(400)--排序范例
if@doCount!=0
begin
if@strWhere!=
set@strSQL=selectcount(*)asTotalfrom[+@tblName+]where+@strWhere
else
set@strSQL=selectcount(*)asTotalfrom[+@tblName+]
end
--以上代码的意义是假如@doCount传送过去的不是0,就实行总数统计。以下的一切代码都是@doCount为0的情形
else
begin
if@OrderType!=0
begin
set@strTmp=<(selectmin
set@strOrder=orderby[+@fldName+]desc
--假如@OrderType不是0,就实行降序,这句很主要!
end
else
begin
set@strTmp=>(selectmax
set@strOrder=orderby[+@fldName+]asc
end
if@PageIndex=1
begin
if@strWhere!=
set@strSQL=selecttop+str(@PageSize)++@strGetFields+from[+@tblName+]where+@strWhere++@strOrder
else
set@strSQL=selecttop+str(@PageSize)++@strGetFields+from[+@tblName+]+@strOrder
--假如是第一页就实行以上代码,如许会加速实行速率
end
else
begin
--以下代码付与了@strSQL以真正实行的SQL代码
set@strSQL=selecttop+str(@PageSize)++@strGetFields+from[
+@tblName+]where[+@fldName+]+@strTmp+([+@fldName+])from(selecttop+str((@PageIndex-1)*@PageSize)+[+@fldName+]from[+@tblName+]+@strOrder+)astblTmp)+@strOrder
if@strWhere!=
set@strSQL=selecttop+str(@PageSize)++@strGetFields+from[
+@tblName+]where[+@fldName+]+@strTmp+([
+@fldName+])from(selecttop+str((@PageIndex-1)*@PageSize)+[
+@fldName+]from[+@tblName+]where+@strWhere+
+@strOrder+)astblTmp)and+@strWhere++@strOrder
end
end
exec(@strSQL)
GO