1

我正在尝试在存储过程中创建并调用临时表。我想要完成的是将年度数据与季度数据相结合。例如:我有一个包含 2013 年数据的字段。要获得按年份分组的年度数据,要获得季度数据,我按季度分组。我通常会使用年度视图并在季度存储过程中调用该视图。我试图这样做的原因是因为我们不能使用每个开发人员的视图。所以为了解决这个问题,我用年度数据制作了一个临时表。(见下面的代码)当我执行这个时,它工作正常,但是当我尝试将存储过程添加到 Devexpress 时,它不包含任何字段。这是我第一次尝试临时表,所以如果有任何错误或更好的方法来写这个,请告诉我。谢谢您的帮助。

CREATE TABLE #StdEcoYearlyData1(
  CaseCaseId int , 
  EcoYear int, 
  NetInvY  float, 
  NDCashY  float, 
  DiscCashY  float, 
  GrossGasY  float, 
  GrossOilY  float, 
  NetProdTaxY  float, 
  NetOpCostY  float,
  WellCostY  float, 
  NetOilY  float, 
  CoNetRevOilY  float, 
  CoNetRevGasY  float, 
  NetGasY  float, 
  NetLocalTaxY  float, 
  NetFixedCostY  float, 
  NetOtherCostY  float, 
  NetProfitY  float, 
  NetTransCostY  float
)

INSERT INTO #StdEcoYearlyData1 (
  CaseCaseId   , 
  EcoYear  , 
  NetInvY  , 
  NDCashY  , 
  DiscCashY  , 
  GrossGasY  , 
  GrossOilY  , 
  NetProdTaxY  , 
  NetOpCostY  ,
  WellCostY  , 
  NetOilY  , 
  CoNetRevOilY  , 
  CoNetRevGasY  , 
  NetGasY  , 
  NetLocalTaxY  , 
  NetFixedCostY  , 
  NetOtherCostY  , 
  NetProfitY  , 
  NetTransCostY  )
SELECT  rcl.CaseCaseId AS CaseId,  YEAR(rce.ecodate) as EYear,
  SUM(rce.NetInv) AS NetInvY, SUM(rce.NDCash) AS NDCashY, 
  SUM(rce.DiscCash) AS DiscCashY, SUM(rce.GrossGas) AS GrossGasY, 
  SUM(rce.GrossOil) AS GrossOilY, SUM(rce.NetProdTax) AS NetProdTaxY, 
  SUM(rce.NetOpCost) AS NetOpCostY, SUM(rce.WellCost) AS WellCostY, 
  SUM(rce.NetOil) AS NetOilY, SUM(rce.CoNetRevOil) AS CoNetRevOilY, 
  SUM(rce.CoNetRevGas) AS CoNetRevGasY, SUM(rce.NetGas) AS NetGasY, 
  Sum(rce.NetLocalTax) as NetLocalTaxY, Sum(rce.NetFixedCost) as NetFixedCostY, 
  Sum(rce.NetOtherCost) as NetOtherCostY, Sum(rce.NetProfit) as NetProfitY, 
  Sum(rce.NetTransCost) as NetTransCostY
from PhdRpt.RptCaseEco rce
   INNER JOIN PhdRpt.ReportCaseList rcl ON 
     rce.ReportRunCaseId = rcl.ReportRunCaseId
 group by rce.reportruncaseid,rcl.CaseCaseId,year(rce.EcoDate)


 select 
  rcl.CaseCaseId AS CaseId, 
  EcoYear  , 
  DATEPART(qq,rce.EcoDate) as Quarter,
  NetInvY  , 
  NDCashY  , 
  DiscCashY  , 
  GrossGasY  , 
  GrossOilY  , 
  NetProdTaxY  , 
  NetOpCostY  ,
  WellCostY  , 
  NetOilY  , 
  CoNetRevOilY  , 
  CoNetRevGasY  , 
  NetGasY  , 
  NetLocalTaxY  , 
  NetFixedCostY  , 
  NetOtherCostY  , 
  NetProfitY  , 
  NetTransCostY,  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, 
  Sum(rce.NetLocalTax) as NetLocalTaxSum, Sum(rce.NetFixedCost) as NetFixedCostSum, 
  Sum(rce.NetOtherCost) as NetOtherCostSum, Sum(rce.NetProfit) as NetProfitSum, 
  Sum(rce.NetTransCost) as NetTransCostSum
 from PhdRpt.RptCaseEco rce
   INNER JOIN PhdRpt.ReportCaseList rcl ON 
     rce.ReportRunCaseId = rcl.ReportRunCaseId 
   INNER JOIN #StdEcoYearlyData1 sey on
    rce.ReportRunCaseId =  sey.CaseCaseId and 
    year(rce.ecodate) = sey.EcoYear
  group by 
  EcoYear  , 
  NetInvY  , 
  NDCashY  , 
  DiscCashY  , 
  GrossGasY  , 
  GrossOilY  , 
  NetProdTaxY  , 
  NetOpCostY  ,
  WellCostY  , 
  NetOilY  , 
  CoNetRevOilY  , 
  CoNetRevGasY  , 
  NetGasY  , 
  NetLocalTaxY  , 
  NetFixedCostY  , 
  NetOtherCostY  , 
  NetProfitY,
  NetTransCostY, 
  rcl.CaseCaseId,
  YEAR(rce.EcoDate),
  DATEPART(qq,rce.EcoDate)

  order by rcl.CaseCaseId


drop table #StdEcoYearlyData1

这是代码的结果

4

0 回答 0