Another page stored procedure

xiaoxiao2021-03-06  48

Written to Haofang's comment system. Four pagination status 1 Request page = first page 2 request page <= total page / 23 request page> Total page / 24 request page = last page

However, the implementation of the last page is not very good, I don't know what is simple. I have no simple way. I have a request page = Total page number / 2, I don't know what it is relatively simple. There is an article above the day. I forgot to find the page. It seems that it is necessary to write a small system to manage your own things.

/ * Author: SLIGHTBOY Created: 2004-12-3 Modified: 2004-12-8 Modified: 2004-12-9 Date Modified: 2004-12-10 Date Modified: 2004-12-13 memory effect: News Comments list of data Base: [Cga_News_Comment_t] input variables: @Sort_ID @Comment_Approve reference number shows the number of record type comprising an @PageSize pages @PageCount @PageRequest request data pages @AbsolutePage this page @RecordCount records output variables: * / CREATE PROCEDURE dbo.sp_CGA_NewsComment_List @Sort_ID INT, @Comment_Approve BIT = NULL, @PageSize INT = 20, @PageRequest INT = 1, @PageCount INT = 0 OUTPUT, @AbsolutePage INT = 1 OUTPUT, @RecordCount INT = 0 OUTPUTAS DECLARE @SqlQueryString VARCHAR (8000) Declare @SqlQuerycondition VARCHAR (200) - Initialization General Information Set @absolutePage = @pageRequest

- Query settings - Declare @SqlQueryKey Varchar (20) - Declare @sqlQueryColumn varchar (200) - Declare @sqlQueryTable Varchar (20) - Start Query Initialization

SET NOCOUNT ON - Get initial information if (@comment_approve <> null) Begin - Query Conditions Set @SQLQueryCondition = 'Sort_ID =' STR (@Sort_ID) 'and Comment_Approve =' Str (@comment_approve) - calculation Total reviews SELECT @RecordCount = COUNT (comment_Id) FROM [Cga_News_Comment_t] WHERE Sort_ID = @Sort_ID AND Comment_Approve = @Comment_Approve END Else BEGIN - query SET @SqlQueryCondition = 'Sort_ID =' STR (@Sort_ID) - calculation Total reviews Select @RecordCount = count (comment_id) from [cga_news_comment_t] where sort_id = @Sort_id End - get the number of comments Top number set @PageCount = CEILING (Cast (@Recordcount as float) / @ Pagesize) - END query initialization

- Start paging logic IF (@PageRequest = 1) BEGIN SET @AbsolutePage = 1 SET @SqlQueryString = 'SELECT TOP' STR (@PageSize) 'Comment_Id, User_Id, User_Name, Comment_Content, User_Ip, Add_Date, Comment_Approve FROM [Cga_News_Comment_t ] WHERE ' @SqlQueryCondition ' ORDER BY comment_Id DESC 'END Else IF (@PageRequest> = @PageCount) BEGIN SET @AbsolutePage = @PageCount SET @SqlQueryString =' SELECT TOP ' STR (@PageSize) ' comment_Id, user_Id , User_Name, Comment_Content, user_Ip, Add_Date, Comment_Approve FROM [Cga_News_Comment_t] WHERE ' @SqlQueryCondition ' AND comment_Id <= (SELECT MAX (comment_Id) FROM (SELECT TOP ' STR (@RecordCount - ABS (@PageSize * (@PageCount - 1))) 'comment_Id FROM [Cga_News_Comment_t] WHERE' @SqlQueryCondition 'ORDER BY comment_Id ASC) AS TableTemp) ORDER BY comment_Id DESC' END Else IF (@PageRequest <= @PageCount / 2) BEGIN SET @Sq lQueryString = 'SELECT TOP' STR (@PageSize) 'Comment_Id, User_Id, User_Name, Comment_Content, User_Ip, Add_Date, Comment_Approve FROM [Cga_News_Comment_t] WHERE' @SqlQueryCondition 'AND Comment_Id <(SELECT MIN (Comment_Id) FROM (SELECT TOP ' STR (@PageSize * (@PageRequest - 1)) ' Comment_id from [cga_news_comment_t] where ' @SqlQueryCondition '

ORDER BY Comment_Id DESC) AS TableTemp) ORDER BY Comment_Id DESC 'END Else IF (@PageRequest> @PageCount / 2) BEGIN SET @SqlQueryString =' SELECT TOP ' STR (@PageSize) ' Comment_Id, User_Id, User_Name, Comment_Content, user_Ip, Add_Date, Comment_Approve FROM [Cga_News_Comment_t] WHERE ' @SqlQueryCondition ' AND comment_Id <(SELECT MAX (comment_Id) FROM (SELECT TOP ' STR (@RecordCount - (@PageSize * (@PageRequest - 1) - 1)) 'comment_Id FROM [Cga_News_Comment_t] WHERE' @SqlQueryCondition 'ORDER BY comment_Id ASC) AS TableTemp) ORDER BY comment_Id DESC' END Else BEGIN - does not carry this logical PRINT @SqlQueryString END-- PRINT @SqlQueryString - SELECT @ Recordcount as '@recordcount', @PageSize as '@Pagesize', @PageRequest as '@pageRequest' Exec (@sqlQueryString) Go

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

New Post(0)