-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcc medical detail fees.sql
77 lines (67 loc) · 2.75 KB
/
hcc medical detail fees.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
declare @EvaluationPeriodKey int = 20221031
declare @EvaluationDate date = (select DateVal from TMMWarehouse..DimDate where DateKey=@EvaluationPeriodKey )
if exists (select * from tempdb.dbo.sysobjects o where o.xtype in ('U') and o.id = object_id(N'tempdb..#a'))
DROP TABLE #a
if exists (select * from tempdb.dbo.sysobjects o where o.xtype in ('U') and o.id = object_id(N'tempdb..#b'))
DROP TABLE #b
select SUM(CededProducerCommission) as SourceCommissionPaidAmount,
sum(CededFrontFee+CededMgmtFee) as SourceFeesAmount,
Sum(CededTax) as SourceTaxesAmount
from Tmmwarehouse_Staging..src_HCCMedical_Detail_Archive
where FinancialDate='2022/10'
select
SUM(CommissionPaidAmount) as TargetCommissionPaidAmount,
SUM(FeesAmount) as TargetFeesAmount,
SUM(TaxesAmount) as TargetTaxesAmount
FROM
TMMWarehouse.dbo.FactMiscFeesAccountingPeriodSnapshot f
JOIN
TMMWarehouse.dbo.DimASLOB a on f.ASLOBKey = a.ASLOBKey
JOIN
TMMWarehouse.dbo.DimCompany c on f.ReportingCompanyKey = c.CompanyKey
JOIN
TMMWarehouse.dbo.DimPolicy p on f.PolicyKey = p.PolicyKey
WHERE
f.SourceSystemKey = 4203
and
AccountingPeriodKey = @EvaluationPeriodKey
select concat(PolicyNumber,'_',PolicyID) as PolicyNumber, SUM(CededProducerCommission) as SourceCommissionPaidAmount,
sum(CededFrontFee+CededMgmtFee) as SourceFeesAmount,
Sum(CededTax) as SourceTaxesAmount
into #a
from Tmmwarehouse_Staging..src_HCCMedical_Detail_Archive
where FinancialDate='2022/10'
group by concat(PolicyNumber,'_',PolicyID)
select f.PolicyNumber, SUM(CommissionPaidAmount) as TargetCommissionPaidAmount,
SUM(FeesAmount) as TargetFeesAmount,
SUM(TaxesAmount) as TargetTaxesAmount
into #b
FROM
TMMWarehouse.dbo.FactMiscFeesAccountingPeriodSnapshot f
JOIN
TMMWarehouse.dbo.DimASLOB a on f.ASLOBKey = a.ASLOBKey
JOIN
TMMWarehouse.dbo.DimCompany c on f.ReportingCompanyKey = c.CompanyKey
JOIN
TMMWarehouse.dbo.DimPolicy p on f.PolicyKey = p.PolicyKey
WHERE
f.SourceSystemKey = 4203
and
AccountingPeriodKey = @EvaluationPeriodKey
group by f.PolicyNumber
Select
@EvaluationPeriodKey as AccountingPeriodKey,
ISNULL(a.PolicyNumber, b.PolicyNumber) as ClaimNumber,
a.SourceCommissionPaidAmount as SourceCommissionPaidAmount,
a.SourceFeesAmount as SourceFeesAmount,
a.SourceTaxesAmount as SourceTaxesAmount,
b.TargetCommissionPaidAmount as TargetCommissionPaidAmount,
b.TargetFeesAmount as TargetFeesAmount,
b.TargetTaxesAmount as TargetTaxesAmount
From #a a
FULL OUTER JOIN #b b
On a.PolicyNumber = b.PolicyNumber
Where
IsNull(a.SourceCommissionPaidAmount, 0.00) <> IsNull(b.TargetCommissionPaidAmount, 0.00) or
IsNull(a.SourceFeesAmount, 0.00) <> IsNull(b.TargetFeesAmount, 0.00) or
IsNull(a.SourceTaxesAmount, 0.00) <> IsNull(b.TargetTaxesAmount, 0.00)