当前位置: 代码迷 >> Sql Server >> 公司业务系统的分页存储过程,该怎么解决
  详细解决方案

公司业务系统的分页存储过程,该怎么解决

热度:4   发布时间:2016-04-27 11:31:36.0
公司业务系统的分页存储过程
老大让我研究一下分页存储过程,可惜小弟不才,只能求助各位大侠了,我在百度查了一下,这个存储过程网上也有,网上那个没有解释看不明白,这个也是,而且复杂一点 ,希望余下 --? --文字 的部分可以给出每句的解释或者那句话的作用、用途,因为本人实在太菜了
SQL code
USE [XXDB]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO------------------------ Name: CT_Append Store Procedure-- Author: xx-- DateTime:xx-- Description: Data TableCT_Append , Get List-----------------------------/*@PageIndex @TotalRecords */    ALTER PROCEDURE [dbo].[CT_Append_Search](    @VC_A_SNNO varchar(50),    @VC_OC_UserName varchar(50),    @VC_OC_Company varchar(50),    @VC_A_CardNO varchar(50),    @CardType int,    @VC_A_AppendType varchar(50),    @VC_TicketType varchar(50),    @VC_TicketNO varchar(50),    @StartDate varchar(50),    @EndDate varchar(50),    @PageIndex int,    @TotalRecords int)ASBEGIN    DECLARE @Page int    DECLARE @PageLowerBound int    DECLARE @PageUpperBound int    DECLARE @RowsToReturn int    SET @Page = (@PageIndex - 1)    --?    -- First set the rowcount    SET @RowsToReturn = @TotalRecords * (@Page + 1)  --这句话有什么用    SET ROWCOUNT @RowsToReturn                        --这里是不是语法错误,还是赋值语句?    -- Set the page bounds    SET @PageLowerBound = @TotalRecords * @Page            --?    SET @PageUpperBound = @PageLowerBound + @TotalRecords + 1    -- Create a temp table to store the select results    CREATE TABLE #PageIndex     (        IndexId int IDENTITY (1, 1) NOT NULL,             --?        VC_A_SNNO varchar(50)    )    Declare @ConSQL varchar(2000)    Declare @StrSQL varchar(2000)    set @StrSQL='INSERT INTO #PageIndex (VC_A_SNNO)    SELECT [VC_A_SNNO] FROM [CT_Append] a LEFT OUTER JOIN                CT_OuterCard b ON a.VC_A_CardNO = b.VC_OC_CardNO LEFT OUTER JOIN                CT_InhouseCard c ON a.VC_A_CardNO = c.VC_IC_CardNO where a.RecordNO<>0'    set @ConSQL=''    if(@VC_A_SNNO<>'')    begin        set @[email protected] + ' and a.VC_A_SNNO like ''%' + @VC_A_SNNO +'%'''    end    if(@VC_OC_UserName<>'')    begin        set @[email protected] + ' and b.VC_OC_UserName like ''%' + @VC_OC_UserName+'%'''    end    if(@VC_OC_Company<>'')    begin        set @[email protected] + ' and b.VC_OC_Company like ''%' + @VC_OC_Company+'%'''    end        if(@VC_A_CardNO<>'')    begin        set @[email protected] + ' and a.VC_A_CardNO like ''%' + @VC_A_CardNO+'%'''    end        if(@CardType>0)    begin        set @[email protected] + ' and a.I_A_CardType=' + cast(@CardType as varchar(2))    end        if(@VC_A_AppendType<>'')    begin        set @[email protected] + ' and a.VC_A_AppendType=''' + @VC_A_AppendType+''''    end            if(@VC_TicketType<>'')    begin        set @[email protected] + ' and a.VC_TicketType=''' + @VC_TicketType+''''    end        if(@VC_TicketNO<>'')    begin        set @[email protected] + ' and a.VC_TicketNO=''' + @VC_TicketNO+''''    end        if(@StartDate<>'')    begin        set @[email protected] + ' and a.D_A_AppendDateTime>=''' + @StartDate+''''    end        if(@EndDate<>'')    begin        set @[email protected] + ' and a.D_A_AppendDateTime<=''' + @EndDate+''''    end            Execute(@StrSQL + @ConSQL +' order by a.D_A_AppendDateTime DESC')        SELECT        c.VC_A_SNNO,        [VC_A_AppendType] ,        [VC_A_CardNO] ,        [I_A_CardType] ,        [I_A_PointToOil] ,        [VC_TicketType] ,        [VC_TicketNO] ,        [DE_A_BAmount] ,        [DE_A_AppendAmount] ,        [DE_A_AAmount] ,        [D_A_AppendDateTime] ,        [VC_A_Remark] ,        [VC_A_OperatorNO]     FROM [CT_Append] c , #PageIndex PageIndex      --不明白临时表在这里有什么用?    WHERE        c.VC_A_SNNO = PageIndex.VC_A_SNNO AND        PageIndex.IndexID > @PageLowerBound AND        PageIndex.IndexID < @PageUpperBound            Execute('SELECT COUNT(VC_A_SNNO) AS TotalRecords FROM [CT_Append] a LEFT OUTER JOIN          --为什麽要连接其他的表                CT_OuterCard b ON a.VC_A_CardNO = b.VC_OC_CardNO LEFT OUTER JOIN                CT_InhouseCard c ON a.VC_A_CardNO = c.VC_IC_CardNO where a.RecordNO<>0' + @ConSQL)
  相关解决方案