Guest User

Untitled

a guest
Aug 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. declare
  2. @BatchKey INT = 1, @ParentBatchKey INT = 1,
  3. @QuoteRef varchar(50) = 'Q00018249',
  4. @MpanRef varchar(50) = '1425431100004'
  5.  
  6.  
  7. SELECT DISTINCT
  8. ISNULL(c.ContractReference,-1) AS [ContractReference] ,
  9. ISNULL(d_cd.ContractDetailsKey,-1) AS [ContractDetailsKey] ,
  10. -1 AccountManagerKey,
  11. -1 SegmentationKey,
  12. ISNULL(d_tpi.TpiKey,-1) AS [TpiKey] ,
  13. ISNULL(d_cu.CustomerKey,-1) AS [CustomerKey] ,
  14. ISNULL(d_p.ProductKey,-1) AS [ProductKey] ,
  15. -1 as PayPointKey,
  16. -1 AS [GspBandingKey], --Not used in Junifer ESOB
  17. ISNULL(d_pps.[ProductPricingStructureKey],-1) AS [ProductPricingStructureKey],
  18. ISNULL(d_tou.TouBandingKey,-1) AS [PricingStructureBandingKey],
  19. -1 AS [VolumePointCategoryKey],
  20. ISNULL(d_ppc.PowerPeriodCategoryKey,-1) AS [PowerPeriodCategoryKey],
  21. ISNULL(d_pcat.[PriceComponentAggregationTypeKey],-1) AS [PriceComponentAggregationTypeKey],
  22. -1 AS [MarginRateBandingKey], --Not used in Junifer ESOB
  23. -1 AS [DuosUrcBandingKey], --Not used in Junifer ESOB
  24. -1 AS [ConsumptionToleranceKey],
  25. ISNULL(d_mp.MeterPointKey,-1) AS [MeterPointKey] ,
  26. ISNULL(d.DateKey,-1) AS [ForecastDateKey] ,
  27. -1 AS [ForecastEFADateKey],
  28. ISNULL(d_cw.DateKey,-1) AS [ContractWonDateKey] ,
  29. ISNULL(f.SiteVolumeKwh,0) AS [SiteVolume] ,
  30. ISNULL(f.GspVolumeKwh,0) AS [GspVolume] ,
  31. ISNULL(f.NbpVolumeKwh,0) AS [NbpVolume],
  32. @BatchKey,
  33. @ParentBatchKey,
  34. CAST(f.ForecastKey as NVARCHAR(100)) AS [SourceId]
  35. FROM
  36. [Electricity].[Forecast] f
  37. INNER JOIN Electricity.ContractMeterPoint cmp ON cmp.MeterPointKey = f.MeterPointKey and cmp.ContractKey = f.ContractKey
  38. INNER JOIN Electricity.Contract c on c.ContractKey = cmp.ContractKey
  39. INNER JOIN Electricity.MeterPoint mp ON mp.MeterPointKey = cmp.MeterPointKey
  40.  
  41. --INNER JOIN Electricity.ContractMeterPoint cmp ON cmp.MeterPointKey = mp.MeterPointKey and cmp.ContractKey = c.ContractKey
  42. INNER JOIN Electricity.ProductBundle pb ON c.ProductBundleKey = pb.ProductBundleKey
  43. LEFT JOIN Electricity.Quote q ON c.QuoteKey = q.QuoteKey
  44. LEFT JOIN Gdf.Tender t ON q.TenderKey = t.TenderKey
  45. LEFT JOIN Gdf.Customer cu ON q.CustomerKey = cu.CustomerKey
  46. LEFT JOIN Electricity.ProductBundleAggregationType pbat ON pbat.ProductName = pb.BundleName
  47. LEFT JOIN Dimensional_DW.DimensionElectricity.Product d_p ON d_p.ProductDurableKey = pb.ProductBundleKey
  48. LEFT JOIN Dimensional_DW.Dimension.Tpi d_tpi ON d_tpi.TpiDurableKey = c.TpiKey
  49. LEFT JOIN Dimensional_DW.DimensionElectricity.ProductPricingStructure d_pps ON d_pps.ProductPricingStructureDurableKey = f.PriceStructureKey
  50. LEFT JOIN Dimensional_DW.DimensionElectricity.TouBanding d_tou ON d_tou.TouBandingDurableKey = f.PriceRateKey
  51. LEFT JOIN Dimensional_DW.DimensionElectricity.MeterPoint d_mp ON d_mp.MeterPointDurableKey = cmp.MeterPointKey
  52. LEFT JOIN Dimensional_DW.DimensionElectricity.PriceComponentAggregationType d_pcat ON d_pcat.[TnuosAggregationType] =pbat.[TNUoSAggType] AND d_pcat.[DuosAggregationType] =pbat.[DUoSFixedAvailAggType] AND d_pcat.[DuosUrcAggregationType] =pbat.[DUoSURCAggType] AND d_pcat.[BsuosAggregationType] =pbat.[BSUoSAggType] AND d_pcat.[ROAggregationType] =pbat.[ROAggType]
  53. LEFT JOIN Dimensional_DW.Dimension.Date AS d ON d.DateKey = CAST(CONVERT(NVARCHAR(8), f.DeliveryDate, 112) AS INT)
  54. LEFT JOIN Dimensional_DW.Dimension.Date AS d_cw ON d_cw.DateKey = CAST(CONVERT(NVARCHAR(8), c.QuoteWonDate, 112) AS INT)
  55. LEFT JOIN Dimensional_DW.DimensionElectricity.PowerPeriodCategory d_ppc ON d_ppc.HhPeriod = f.Period
  56. LEFT JOIN Dimensional_DW.Dimension.Customer d_cu ON d_cu.CustomerDurableKey = cu.CustomerKey
  57. LEFT JOIN Dimensional_DW.DimensionElectricity.ContractDetails d_cd ON d_cd.ContractDetailsDurableKey = c.ContractKey
  58.  
  59. WHERE 1=1
  60. and c.ContractReference = @QuoteRef
  61. and c.QuoteWonDate IS NOT NULL
  62. and c.QuoteKey <> -1
  63. --(SELECT distinct C.ContractKey FROM Electricity.Contract WHERE ContractReference = @QuoteRef and c.QuoteWonDate IS NOT NULL and c.QuoteKey <> -1)
  64. --(SELECT distinct C1.ContractKey FROM Electricity.Contract c1 WHERE c1.ContractReference = @QuoteRef and c1.QuoteWonDate IS NOT NULL and c1.QuoteKey <> -1)
  65. and mp.MpanID = @MpanRef
  66. --and c.ContractKey = 18235
  67. --and d.DateKey = 20180522
  68. order by [ForecastDateKey]
Add Comment
Please, Sign In to add comment