A relatively practical big data volume paging store process (select Blog from Jierry007)

xiaoxiao2021-03-06  17

Create Proc sp_publicTurnPageWebsite (@tbname nvarchar (100) = ', - table name, such as Pinyin @Pagesize INT = 10, - The number of records per page, the default is 10 @curpage int = 1, - means current page 1 @Keyfield nvarchar (100) = 'ID', - Key Field name, default is ID, the field requirement is the index in the table or the field @KeyascDesc nvarchar (4) = 'asc', - Lifting, descending order, default is ascending ASC, descending is desc @fields nvarchar (500) = '*', - the selected column name, default is all @condition nvarchar (200) = ', --where conditions, default is empty @ORDER NVARCHAR (200) = '' - Sort Condition, Default As Empty) WINCRYPTION As IF @tbname = 'Begin Raiserror (' Please specify a table name! ', 11, 1) Return End if @Pagesize <= 0 or @Curpage <0 Begin Raiserror ('The number of current pages and the number of records per page must be greater than zero!', 11, 1) Return end if @keyascdesc = 'dec' set @keyascdesc = '' 'set @condition =' where ' @condition declare @SQL nVARCHAR (2000) set @SQL =' = = @curpage = 1 set @SQL = @SQL 'SELECT TOP' CAST (@PageSize As nvarchar (20)) '' @fields 'from' @tbname @Condition ' @Order else begin declare @itopnum int set @itopnum = @PageSize * (@curpage - 1) set @sql = @SQL 'Declare @SlastValue NVARCH Ar (100) ' char (13) set @SQL = @SQL ' SELECT TOP ' CAST (@itopnum as nvarchar (20)) ' @ SlastValue = ' @keyfield ' from ' @TBNAME @ Condition '' @order

char (13) declare @ Condition2 nvarchar (200) if @Condition = '' set @ Condition2 = 'where' @KeyField @KeyAscDesc '@sLastValue' else set @ Condition2 = 'and' @KeyField @KeyAscDesc '@SlastValue' set @SQL = @SQL 'SELECT TOP' CAST (@Pagesize As nvarchar (20)) '' @fields 'from' @tbname @Condition @ Condition2 @Order End Execute sp_executesql @SQL

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

New Post(0)