0

我有一个存储过程,我想输出一个可被 15 整除的行数。例如,我有一个输出 33 行但每页恰好包含 15 行的存储过程。在只有 3 行的最后一页上,间距搞砸了。因为行数始终是动态的,所以我认为将行数设置为可被 15 整除的数字会更容易。所以在这种情况下,它将添加 12 个空白行以保持间距正确。

这是我的代码:

SELECT  ROW_NUMBER() OVER ( ORDER BY YEAR(rce.Ecodate) ) AS Row ,
        rce.ReportRunCaseId AS CaseId ,
        YEAR(rce.EcoDate) AS EcoYear ,
        SUM(rce.NetInv) AS NetInvSum ,
        SUM(rce.NDCash) AS NDCashSum ,
        SUM(rce.DiscCash) AS DiscCashSum ,
        SUM(rce.GrossGas) AS GrossGasSum ,
        SUM(rce.GrossOil) AS GrossOilSum ,
        SUM(rce.NetProdTax) AS NetProdTaxSum ,
        SUM(rce.NetOpCost) AS NetOpCostSum ,
        SUM(rce.WellCost) AS WellCostSum ,
        SUM(rce.NetOil) AS NetOilSum ,
        SUM(rce.CoNetRevOil) AS CoNetRevOilSum ,
        SUM(rce.CoNetRevGas) AS CoNetRevGasSum ,
        SUM(rce.NetGas) AS NetGasSum ,
        rce.WellCount ,
        rcl.SortId
FROM    PhdRpt.ReportCaseList AS rcl
        INNER JOIN PhdRpt.RptCaseEco AS rce ON rce.ReportId = rcl.ReportId
                                               AND rce.ReportRunCaseId = rcl.ReportRunCaseId
GROUP BY rcl.SortId ,
        rce.ReportId ,
        rce.ReportRunCaseId ,
        YEAR(rce.EcoDate) ,
        rce.WellCount

我读过我可以使用 INSERT INTO 向表中添加行。我应该使用这样的东西:

INSERT  INTO rce
        SELECT  num - 1
        FROM    T1
        WHERE   ( num % 15 ) = 0 
4

1 回答 1

1
  • 将您在示例中选择的记录插入到临时表中。
  • 然后为要添加的空白行再次插入临时表。
  • 然后从临时表中选择记录作为存储过程的返回值。
于 2013-04-19T18:59:23.303 回答