-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path5-create-reconciliation-view.sql
83 lines (71 loc) · 2.37 KB
/
5-create-reconciliation-view.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
78
79
80
81
82
83
-- ============================================================
-- Description:
-- 1. In this query, we create a view to run the reconciliation
-- ============================================================
@recon_view =
use Sys.Admin.SetupView
--provider=Recon.IborVersusAbor
--parameters
aborScope,Text,abor-recon-test,true
iborScope,Text,ibor-recon-test,true
reconDate,Date,2022-03-01,true
----
@@aborScope = select #PARAMETERVALUE(aborScope);
@@iborScope = select #PARAMETERVALUE(iborScope);
@@reconDate = select #PARAMETERVALUE(reconDate);
-- Get ABOR holdings
@abor_data = select
h.PortfolioCode,
i.DisplayName as [InstrumentName],
i.LusidInstrumentId,
i.ClientInternal,
i.Isin,
h.HoldingType,
h.Units
from Lusid.Portfolio.Holding h
join Lusid.Instrument i on (i.LusidInstrumentId = h.LusidInstrumentId)
where h.PortfolioScope = @@aborScope
and h.EffectiveAt = @@reconDate
order by h.HoldingType desc;
-- Get IBOR holdings
@ibor_data = select
h.PortfolioCode,
i.DisplayName as [InstrumentName],
i.LusidInstrumentId,
i.ClientInternal,
i.Isin,
h.HoldingType,
h.Units
from Lusid.Portfolio.Holding h
join Lusid.Instrument i on (i.LusidInstrumentId = h.LusidInstrumentId)
where h.PortfolioScope = @@iborScope
and h.EffectiveAt = @@reconDate
order by h.HoldingType desc;
select
a.PortfolioCode as [Abor_PortfolioCode],
a.InstrumentName as [Abor_InstrumentName],
a.Isin as [Abor_Isin],
a.HoldingType as [Abor_HoldingType],
a.Units as [Abor_Units],
i.Units as [Ibor_Units],
(a.Units - i.Units) as [Units_Diff],
round(((a.Units *1.0) / i.Units) -1 ,5) as [Units_Diff_Pct],
case when (abs(a.Units - i.Units) > 0 or i.Units is null or a.Units is null) then 'Break' else 'NoBreak' end as [ReconStatus]
from @abor_data a
left join @ibor_data i on (a.ClientInternal = i.ClientInternal and i.PortfolioCode = a.PortfolioCode)
union
select
a.PortfolioCode as [Abor_PortfolioCode],
a.InstrumentName as [Abor_InstrumentName],
a.Isin as [Abor_Isin],
a.HoldingType as [Abor_HoldingType],
a.Units as [Abor_Units],
i.Units as [Ibor_Units],
(a.Units - i.Units) as [Units_Diff],
round(((a.Units *1.0) / i.Units) -1 ,5) as [Units_Diff_Pct],
case when (abs(a.Units - i.Units) > 0 or i.Units is null or a.Units is null) then 'Break' else 'NoBreak' end as [ReconStatus]
from @ibor_data i
left join @abor_data a on (a.ClientInternal = i.ClientInternal and i.PortfolioCode = a.PortfolioCode)
;
enduse;
select * from @recon_view wait 10;