Store procedure paging

xiaoxiao2021-03-06  43

Shortly before 9CBS, I have to look at the efficiency of paging on 9CBS. Many masters should not use the self-contained paging method of DataGrid without using large data, but should use the stored procedure. There are also many ways to use stored procedures, select .... top ....., not .....in ...... After considering the end, I still use SELECT .... TOP .... This stored procedure is made. The source code I use is: (according to a paragraph in the lowermost post, change it yourself, add this paragraph to get the total number of conditions) Create Procedure getPageRecords @tblname varchar (255), @fldname varchar (255), @ PageSize Int = 12, @PageIndex INT = 1, @iscount bit = 0, @ORDERTYPE BIT = 0, @strwhere varchar (1000) = '' / *

************ *********************************************************** ******************************************* Name: getPageRecords feature: Gets the total number of data or data per page per page: input: @TBLNAME table name @fldname Used Field @PageSize Each page The number of data bars @PageIndex page @iscount returns the total number of records, non-0 value returns Total number @ORDERTYPE Sets the sort type, non-0 value is descended @Strwhere query conditions (attention: don't add where) -------------------------- --------------------------------

@STRSQL primary sentence @strtmp temporary variable @StrORDER Sort Type Data Source: Documents Newsletter: Yang Wenzi Date: 2004/9/21 Note: This stored process is more common, if you want to further improve efficiency, you can provide specializes in this application SELECT statement replaces select * ************************************************************* *********************************************************** ************* * / as

Declare @strsql varchar (2000) - Proficiency Declare @strtmp varchar (1000) - Temporary Variable Declare @strORDER VARCHAR (1000) - Sort Type

IF @ORDERTYPE! = 0BEGIN SET @STRTMP = "<(Select Min" set @strorder = "Order by [" @fldname "] desc" endelsebegin set @strtmp = "> (Select Max" set @strorder = "ORDER BY [" @fldname "] ASC "endset @strsql =" select top " str (@PageSize) " * from [" @TBLNAME "] where [" @fldname "] " @strtmp "([" @Fldname "]) from (select top" Str ((@ PageIndex-1) * @ PageSize) "[" @fldname "] from [" @TBLNAME "]" @strorder ") as tbltmp)" @strorder

If @strwhere! = '' set @strsql = "select top" str (@PageSize) "* from [" @TBLNAME "] where [" @fldname "]" @strtmp "([[[ " @Fldname "]) from (SELECT TOP " STR ((@ PageIndex-1) * @ PageSize) " [" @fldname "] from [" @TBLNAME "] Where (" @ Strwhere ")" @strorder ") as tbltmp) and (" @strwhere ")" @strorder

IF @PageIndex = 1begin set @strtmp = "" "if @strwhere! = '' set @strtmp =" Where (" @strwhere ") "

Set @STRSQL = "SELECT TOP" STR (@PageSize) "* from [" @TBLNAME "]" @strtmp "" @strorderendif @iscount! = 0 if @Strwhere! = 'set @ strsql = "Select Count (*) As Total from [" @TBLNAME "] Where (" @ Strwhere ")" Else Set @strsql = "Select Count (*) As Total from [" @tblname "] "

EXEC (@strsql) Go

-------------------------------------------------- -------------------------------------------------- -------------------------- Related Discussion in this: http://community.9cbs.net/expert/topicview.asp? Id = 3292678

转载请注明原文地址:https://www.9cbs.com/read-113441.html

New Post(0)