/
5-assign-lei-to-portfolio.sql
38 lines (33 loc) · 1.25 KB
/
5-assign-lei-to-portfolio.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
-- ================================================================
-- Description:
-- In this query, we assign Portfolios to a Legal Entity Identifier
-- ================================================================
@@scope = select 'ibor';
-- 1. Create view with LEIs and portfolios joined on custodian name.
@portfolio_data =
use Drive.Excel
--file=/luminesce-examples/custodians.xlsx
--worksheet=portfolios
enduse;
@custodians_data =
use Drive.Excel
--file=/luminesce-examples/custodians.xlsx
--worksheet=custodians
enduse;
@portfolio_custodian_data = select p.port_code, c.lei
from @portfolio_data p
inner join (
select lei, custodian_code
from @custodians_data
) c
on p.custodian_code = c.custodian_code;
-- 2. Define a relationship between LEI and Portfolio
@assign_relationships =
select 'LegalEntity' as EntityType, 'LEI' as EntityCode, 'default' as EntityScope, lei as EntityValue, port_code as
RelatedEntityCode, @@scope as RelatedEntityScope, 'Portfolio' RelatedEntityType, 'LEIToPortfolio' as RelationshipCode,
@@scope as RelationshipScope
from @portfolio_custodian_data;
-- 3. Write the relationship to Lusid.Relationship.Writer and print results to console
select *
from Lusid.Relationship.Writer
where ToWrite = @assign_relationships;