select distinct -- date 4000-12-31 as end_date dds_id_new collateral_c

 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
select distinct
--, date'4000-12-31' as end_date
dds_id_new
, collateral_contract_number
, collateral_contract_open_date
, collateral_contract_close_date
, to_char(collateral_contract_currency)
, collateral_contract_amount
, to_char(dropped_flg)
from
(select tb1.*, min(dds_id) over(partition by collateral_contract_id, src_id) as dds_id_new
from dds.collateral_contract tb1 where end_date=date'4000-12-31'
) tb2
where to_date('01.01.2018','dd.mm.yyyy') between tb2.collateral_contract_begin_date and tb2.collateral_contract_end_date
and dds_id_new='101000003636'
union
select distinct
SKP_COLLATERAL_AGREEMENT_ID,
COLLATERAL_AGREEMENT_NUM,
COLLATERAL_AGREEMENT_OPEN_DATE,
COLLATERAL_AGR_CLOSE_DATE,
COLLATERAL_AGR_CURRENCY_CODE,
COLLATERAL_AGREEMENT_AMOUNT,
DROPPED_FLAG
from dwh.DT_COLLATERAL_AGREEMENT
where to_date('01.01.2018','dd.mm.yyyy') between begin_date and end_date
and SKP_COLLATERAL_AGREEMENT_ID = 101000003636