我有一个存储过程,我想输出一个可被 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