Open bryanramirez1 opened 1 week ago
Note: The updated scripts for Steps 2, 3 and 4 can be reused on multiple EASEY databases.
select pgv.*,
(
' '
|| 'select '
|| '''' || pgv.Vendor_Id || ''' as Vendor_Id, '
|| '''' || pgv.Vendor_Name || ''' as Vendor_Name, '
|| decode( pgv.Activation_Date, null, 'NULL', 'to_date( ''' || to_char( pgv.Activation_Date, 'yyyy-mm-dd') || ''', ''yyyy-mm-dd'' )' ) || ' as Activation_Date, '
|| decode( pgv.Deactivation_Date, null, 'NULL', 'to_date( ''' || to_char( pgv.Deactivation_Date, 'yyyy-mm-dd') || ''', ''yyyy-mm-dd'' )' ) || ' as Deactivation_Date, '
|| pgv.Active_Ind || ' as Active_Ind, '
|| decode( pgv.Userid, null, 'NULL', '''' || pgv.Userid || '''' ) || ' as Userid, '
|| decode( pgv.Add_Date, null, 'NULL', 'to_timestamp( ''' || to_char( pgv.Add_Date, 'yyyy-mm-dd hh24:mi:ss') || ''', ''yyyy-mm-dd hh24:mi:ss'' )::timestamp without time zone' ) || ' as Add_Date, '
|| decode( pgv.Update_Date, null, 'NULL', 'to_timestamp( ''' || to_char( pgv.Update_Date, 'yyyy-mm-dd hh24:mi:ss') || ''', ''yyyy-mm-dd hh24:mi:ss'' )::timestamp without time zone' ) || ' as Update_Date '
|| 'union all'
) as Sql_Statement
from PROTOCOL_GAS_VENDOR pgv
order
by pgv.Add_Date,
pgv.Vendor_Id
select *
from camdecmps.PROTOCOL_GAS_VENDOR pgv
where not exists
(
select 1
from (
/* Replace with the select core. */
) exs
where exs.Vendor_Id = pgv.Vendor_Id
)
with
old as
(
select pgv.Vendor_Id,
pgv.Vendor_Name,
pgv.Activation_Date,
pgv.Deactivation_Date,
pgv.Active_Ind,
pgv.Userid,
pgv.Add_Date,
pgv.Update_Date
from camdecmps.PROTOCOL_GAS_VENDOR pgv
),
new as
(
/* Replace with the select core. */
)
select dif.Vendor_Id,
dif.Source_Cd,
dif.Vendor_Name,
dif.Activation_Date,
dif.Deactivation_Date,
dif.Active_Ind,
dif.Userid,
dif.Add_Date,
dif.Update_Date
from (
select dat.Vendor_Id,
'NEW' as Source_Cd,
dat.Vendor_Name,
dat.Activation_Date,
dat.Deactivation_Date,
dat.Active_Ind,
dat.Userid,
dat.Add_Date,
dat.Update_Date
from ( select * from new except select * from old ) dat
union
select dat.Vendor_Id,
'OLD' as Source_Cd,
dat.Vendor_Name,
dat.Activation_Date,
dat.Deactivation_Date,
dat.Active_Ind,
dat.Userid,
dat.Add_Date,
dat.Update_Date
from ( select * from old except select * from new ) dat
) dif
order
by dif.Vendor_Id,
dif.Source_Cd
merge
into camdecmps.PROTOCOL_GAS_VENDOR snk
using (
/* Replace with the select core. */
) src
on ( snk.Vendor_Id = src.Vendor_Id )
when matched then
update
set snk.Vendor_Name = src.Vendor_Name,
snk.Activation_Date = src.Activation_Date,
snk.Deactivation_Date = src.Deactivation_Date,
snk.Active_Ind = src.Active_Ind,
snk.Userid = src.Userid,
snk.Add_Date = src.Add_Date,
snk.Update_Date = src.Update_Date
when not matched then
insert (
Vendor_Id,
Vendor_Name,
Activation_Date,
Deactivation_Date,
Active_Ind,
Userid,
Add_Date,
Update_Date
)
values (
src.Vendor_Id,
src.Vendor_Name,
src.Activation_Date,
src.Deactivation_Date,
src.Active_Ind,
src.Userid,
src.Add_Date,
src.Update_Date
);
commit;
Beta users (RT 75886) running into vendorid issues as it relates to PGVP vendor ids being outdated in the database. Need to merge updated data in all environments to fix issue.