Guest User

Untitled

a guest
Apr 16th, 2018
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. --DROP TABLE [hmsPrs].[FactPropertyCharge]
  2. --SET ANSI_NULLS ON
  3. --GO
  4.  
  5. --SET QUOTED_IDENTIFIER ON
  6. --GO
  7.  
  8. --SET ANSI_PADDING ON
  9. --GO
  10.  
  11. --CREATE TABLE [hmsPrs].[FactPropertyCharge](
  12. -- [PropertyChargeID] [int] IDENTITY(1,1) NOT NULL,
  13. -- [PropertyID] [bigint] NOT NULL,
  14. -- [TransactionTypeID] [INT] NOT NULL,
  15. -- [ChargeEffectiveFromDateID] [int] NOT NULL,
  16. -- [ChargeEffectiveToDateID] [int] NOT NULL,
  17. -- [CreationDateID] [int] NOT NULL,
  18. -- [SetUpOrAmendTimeID] [int] NOT NULL,
  19. -- [CreatedByOfficerID] [int] NOT NULL,
  20. -- [TerminationOfficerID] [int] NOT NULL,
  21. -- [TerminationDateID] [int] NOT NULL,
  22. -- [TerminationSetupTimeID] [int] NOT NULL,
  23. -- [Value] [numeric](17, 2) NULL,
  24. -- [FixedChargeApplicableInd] [bit] NULL,
  25. -- [BackdatedChargesProcessed] [bit] NULL,
  26. -- [PolicyChargeValue] [numeric](17, 2) NULL,
  27. --) ON [PRIMARY]
  28.  
  29. --GO
  30.  
  31. --SET ANSI_PADDING OFF
  32. --GO
  33.  
  34. --INSERT [hmsPrs].[FactPropertyCharge] ([PropertyID]
  35. -- ,[TransactionTypeID]
  36. -- ,[ChargeEffectiveFromDateID]
  37. -- ,[ChargeEffectiveToDateID]
  38. -- ,[CreationDateID]
  39. -- ,[SetUpOrAmendTimeID]
  40. -- ,[CreatedByOfficerID]
  41. -- ,[TerminationOfficerID]
  42. -- ,[TerminationDateID]
  43. -- ,[TerminationSetupTimeID]
  44. -- ,[Value]
  45. -- ,[FixedChargeApplicableInd]
  46. -- ,[BackdatedChargesProcessed]
  47. -- ,[PolicyChargeValue])
  48.  
  49. --SELECT ISNULL(P.[PropertyID],0) AS [PropertyID],
  50. -- ISNULL(TT.[TransactionTypeID],0) AS [TransactionTypeID],
  51. -- ISNULL(EFF.DateID,0) AS [ChargeEffectiveFromDateID],
  52. -- ISNULL(EFT.DateID,0) AS [ChargeEffectiveToDateID],
  53. -- ISNULL(CD.DateID,0) AS [CreationDateID],
  54. -- ISNULL(ST.[TimeID],0) AS [SetUpOrAmendTimeID],
  55. -- ISNULL(CO.[OfficerID],0) AS [CreatedByOfficerID],
  56. -- ISNULL(TEO.OfficerID,0) AS [TerminationOfficerID],
  57. -- ISNULL(TD.DateID,0) AS [TerminationDateID],
  58. -- ISNULL(TET.[TimeID],0) AS [TerminationSetupTimeID],
  59. -- PC.[Value],
  60. -- PC.[FixedChargeApplicableInd],
  61. -- PC.[BackdatedChargesProcessed],
  62. -- PC.[PolicyChargeValue]
  63.  
  64. --FROM [ims@Transform].[hmsTrn].[PropertyCharge] PC LEFT JOIN
  65. -- [hmsPrs].[DimProperty] P ON PC.PropertySequenceNumber = P.PropertySequenceNumber
  66. -- AND P.[EffectiveFromDate] <= PC.[EffectiveFrom]
  67. -- AND (P.[EffectiveToDate] >= PC.[EffectiveFrom] OR P.[EffectiveToDate] IS NULL) LEFT JOIN
  68. -- [hmsPrs].[DimTransactionType] TT ON PC.TransactionCode = TT.TransactionCode LEFT JOIN
  69. -- [hmsPrs].[DimOfficer] CO ON PC.[CreatedByCouncilOfficeCode] = CO.[OfficerCode] LEFT JOIN
  70. -- [hmsPrs].[DimOfficer] TEO ON PC.[TerminationOfficerCode] = TEO.[OfficerCode] LEFT JOIN
  71. -- [hmsPrs].[DimDate] EFF ON PC.[EffectiveFrom] = EFF.[Date] LEFT JOIN
  72. -- [hmsPrs].[DimDate] EFT ON PC.[EffectiveTo] = EFT.[Date] LEFT JOIN
  73. -- [hmsPrs].[DimDate] TD ON PC.[TerminationDate] = TD.[Date] LEFT JOIN
  74. -- [hmsPrs].[DimTime] ST ON PC.[SetUpOrAmendTime] = ST.SecsInDay LEFT JOIN
  75. -- [hmsPrs].[DimTime] TET ON PC.[TerminationSetupTime] = TET.SecsInDay LEFT JOIN
  76. -- [hmsPrs].[DimDate] CD ON PC.[CreationDate] = CD.[Date]
  77.  
  78. --CREATE VIEW vFactPropertyChargeWithTenancy AS
  79. SELECT fpc.PropertyChargeID,
  80. fpc.PropertyID,
  81. dt.TenancyID,
  82. fpc.TransactionTypeID,
  83. fpc.ChargeEffectiveFromDateID,
  84. fpc.ChargeEffectiveToDateID,
  85. fpc.value,
  86. dt.TenancyCommencementDate,
  87. dt.TenancyTerminationDate,
  88. dt.TenancyNumber,
  89. fpc.CreationDateID,
  90. fpc.SetUpOrAmendTimeID,
  91. fpc.CreatedByOfficerID,
  92. fpc.TerminationOfficerID,
  93. fpc.TerminationDateID,
  94. fpc.TerminationSetupTimeID,
  95. fpc.Value,
  96. fpc.FixedChargeApplicableInd,
  97. fpc.BackdatedChargesProcessed,
  98. fpc.PolicyChargeValue
  99. FROM IMS@Present.HmsPrs.FactPropertyCharge fpc
  100. INNER JOIN IMS@Present.HmsPrs.DimDate effectiveFrom ON effectiveFrom.DateID = fpc.ChargeEffectiveFromDateID
  101. INNER JOIN IMS@Present.HmsPrs.DimDate effectiveTo ON effectiveTo.DateID = fpc.ChargeEffectiveToDateID
  102. INNER JOIN IMS@Present.HmsPrs.DimProperty dp
  103. ON dp.PropertyID = fpc.PropertyID
  104. INNER JOIN IMS@Present.HmsPrs.DimTenancy dt
  105. ON dt.PropertySequenceNumber = dp.PropertySequenceNumber
  106. AND dt.[Current] = 1
  107. AND
  108. (
  109. (
  110. dt.TenancyCommencementDate >= effectiveFrom.Date
  111. AND (dt.TenancyCommencementDate <= effectiveTo.Date OR fpc.ChargeEffectiveToDateID = 0)
  112. AND
  113. (
  114. dt.TenancyTerminationDate <= effectiveTo.Date OR fpc.ChargeEffectiveToDateID = 0
  115. OR dt.TenancyTerminationDate IS NULL
  116. )
  117. )
  118. OR
  119. (
  120. dt.TenancyCommencementDate <= effectiveFrom.Date
  121. AND
  122. (
  123. dt.TenancyTerminationDate >= effectiveFrom.Date OR (fpc.ChargeEffectiveToDateID = 0 AND dt.TenancyTerminationDate >= effectiveFrom.Date)
  124. OR dt.TenancyTerminationDate IS NULL
  125. )
  126. )
  127. )
  128. --WHERE dt.TenancyNumber = 682104
  129. --WHERE fpc.PropertyID IN (SELECT PropertyID FROM IMS@Present.hmsPrs.DimProperty WHERE PropertySequenceNumber = 812)
  130. --AND dt.TenancyID IN (88735, 88695) ORDER BY TenancyID
Add Comment
Please, Sign In to add comment