-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path1-load-data-from-drive.sql
86 lines (69 loc) · 1.98 KB
/
1-load-data-from-drive.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
84
85
86
-- ===============================================================
-- Description:
-- In this query, we upsert a portfolio, instruments and transactions
-- using the data pulled from a file in LUSID Drive.
-- ===============================================================
-- Extract transaction data from LUSID Drive
@txn_data =
use Drive.Excel
--file=/luminesce-examples/pdf-report-data.xlsx
enduse;
-- Set variables for the portfolio's scope and code
@@portfolio_scope = select 'pdf-report';
@@portfolio_code = select 'uk-equity';
@@portfolio_name = select 'UK EQUITY';
-- Define the portfolio data
@create_portfolio =
select 'Transaction' as PortfolioType,
@@portfolio_scope as PortfolioScope,
@@portfolio_code as PortfolioCode,
@@portfolio_name as DisplayName,
'' as Description,
#2000-01-01# as Created,
''as SubHoldingKeys,
'GBP' as BaseCurrency;
-- Upload the portfolio into LUSID
@response_create_portfolio =
select *
from Lusid.Portfolio.Writer
where ToWrite = @create_portfolio;
-- Get instrument data
@equity_instruments =
select
Name as DisplayName,
ISIN as Isin,
ClientInternal as ClientInternal,
SEDOL as Sedol,
'GBP' as DomCcy,
'pdfGeneration' as Scope
from @txn_data;
-- Upload the transformed data into LUSID
@response_write =
select *
from Lusid.Instrument.Equity.Writer
where ToWrite = @equity_instruments;
--Transform data using SQL
@transactions =
select
@@portfolio_scope as PortfolioScope,
@@portfolio_code as PortfolioCode,
t.TransactionID as TxnId,
t.Type as Type,
t.TransactionDate as TransactionDate,
t.SettlementDate as SettlementDate,
t.Units as Units,
t.Price as TradePrice,
t.TotalConsideration as TotalConsideration,
t.Currency as SettlementCurrency,
t.ClientInternal as ClientInternal,
r.LusidInstrumentId as LusidInstrumentId
from @txn_data t
inner join @response_write r
where t.ClientInternal = r.ClientInternal;
-- Upload the transformed data into LUSID
@response =
select *
from Lusid.Portfolio.Txn.Writer
wait 5
where ToWrite = @transactions;
select * from @response;