Мой код может дать мне результат примера 1, но мне действительно нужно получить пример 2. Мне нужно добавить еще одну строку, если два исходных кода не равны нулю и не различаются. Вот мой код, пожалуйста, помогите:
select
cast(coalesce( y.masterentityid, u.masterentityid ) AS VARCHAR) AS MasterEntityId,
cast(coalesce( y.effectiveDate, u.effectiveDate ) AS TIMESTAMP) AS EffectiveDate,
....
....
....
cast(case when u.sourcecode = y.sourcecode then y.sourcecode when u.sourcecode is null or y.sourcecode is null then coalesce(u.sourcecode, y.sourcecode)
else CONCAT(y.sourcecode,chr(10),u.sourcecode) end as VARCHAR ) AS sourcecode,
cast(case when u.masterentityid = y.masterentityid then y.masterentityid when u.masterentityid is null or y.masterentityid is null then coalesce(u.masterentityid, y.masterentityid)
when y.masterentityid is not null and u.masterentityid is not null then y.masterentityid
when y.masterentityid is not null and u.masterentityid is not null then u.masterentityid end as VARCHAR) as masterentityid_2,
cast(case when y._RecordDate > u._RecordDate or u._RecordDate is null then y._RecordDate else u._RecordDate end as Timestamp) as LastChange
from Analytics_ConformYield_latest y
full outer join
ConformUnsubYield_latest u
on y.effectivedate = u.effectivedate
and y.masterentityid = u.masterentityid
Я думаю изменить код на:
cast(case when u.sourcecode = y.sourcecode then y.sourcecode when u.sourcecode is null or y.sourcecode is null then coalesce(u.sourcecode, y.sourcecode)
when y.sourcecode is not null and u.sourcecode is not null then y.sourcecode
when y.sourcecode is not null and u.sourcecode is not null then u.sourcecode end as VARCHAR) as masterentityid_2,