set echo off
set termout on
SPOOL EISN_SYNC.LOG
set time on
-- focus directory level: ..\
-- Scan this listing for errors or problems: Conditional Update.
-- When necessary...
-- Note: 0 rows updated is not an error...
-- Note: 0 rows updated is not an error...
-- Note: 0 rows updated is not an error...
Prompt Please Wait... Synchronizing Table TSMEISN with Data Tables:STORET,STORET1
set termout off
set echo on

-- STORET Database v2.0 Tables:
-- Tables Schema Owner: STORET
-- Tables Schema Owner: STORET
update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMERMSG_IS_NUMBER)
                      from STORET.TSMERMSG    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMERMSG'
  and   exists (select 'x'
                   from STORET.TSMERMSG    wa
                    where TSMERMSG_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMESTRY_IS_NUMBER)
                      from STORET.TSMESTRY    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMESTRY'
  and   exists (select 'x'
                   from STORET.TSMESTRY    wa
                    where TSMESTRY_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMFHU_IS_NUMBER)
                      from STORET.TSMFHU    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMFHU'
  and   exists (select 'x'
                   from STORET.TSMFHU    wa
                    where TSMFHU_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMGEOPA_IS_NUMBER)
                      from STORET.TSMGEOPA    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMGEOPA'
  and   exists (select 'x'
                   from STORET.TSMGEOPA    wa
                    where TSMGEOPA_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSMGEOUN    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMGEOUN'
  and   exists (select 'x'
                   from STORET.TSMGEOUN    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSMLTHUN    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMLTHUN'
  and   exists (select 'x'
                   from STORET.TSMLTHUN    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMMAD_IS_NUMBER)
                      from STORET.TSMMAD    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMMAD'
  and   exists (select 'x'
                   from STORET.TSMMAD    wa
                    where TSMMAD_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSMNAL    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMNAL'
  and   exists (select 'x'
                   from STORET.TSMNAL    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMPRMVL_IS_NUMBER)
                      from STORET.TSMPRMVL    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMPRMVL'
  and   exists (select 'x'
                   from STORET.TSMPRMVL    wa
                    where TSMPRMVL_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMPROLE_IS_NUMBER)
                      from STORET.TSMPROLE    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMPROLE'
  and   exists (select 'x'
                   from STORET.TSMPROLE    wa
                    where TSMPROLE_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMPSR_IS_NUMBER)
                      from STORET.TSMPSR    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMPSR'
  and   exists (select 'x'
                   from STORET.TSMPSR    wa
                    where TSMPSR_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRUOM_IS_NUMBER)
                      from STORET.TSRUOM    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRUOM'
  and   exists (select 'x'
                   from STORET.TSRUOM    wa
                    where TSRUOM_IS_NUMBER>
                       t1.is_number);

-- This table is never flagged for updates (static table)
-- update STORET1.tsmeisn t1
--   set t1.is_number = (select max(TSMRRR_IS_NUMBER)
--                       from STORET.TSMRRR    a)
--   WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
--   and   tsmeisn_name = 'TSMRRR'
--   and   exists (select 'x'
--                    from STORET.TSMRRR    wa
--                     where TSMRRR_IS_NUMBER>
--                        t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSMSIC    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMSIC'
  and   exists (select 'x'
                   from STORET.TSMSIC    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMVSTC_IS_NUMBER)
                      from STORET.TSMVSTC    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMVSTC'
  and   exists (select 'x'
                   from STORET.TSMVSTC    wa
                    where TSMVSTC_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRANLEQ_IS_NUMBER)
                      from STORET.TSRANLEQ    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRANLEQ'
  and   exists (select 'x'
                   from STORET.TSRANLEQ    wa
                    where TSRANLEQ_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRBIOPT_IS_NUMBER)
                      from STORET.TSRBIOPT    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRBIOPT'
  and   exists (select 'x'
                   from STORET.TSRBIOPT    wa
                    where TSRBIOPT_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRCHALS_IS_NUMBER)
                      from STORET.TSRCHALS    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCHALS'
  and   exists (select 'x'
                   from STORET.TSRCHALS    wa
                    where TSRCHALS_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRCHAR_IS_NUMBER)
                      from STORET.TSRCHAR    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCHAR'
  and   exists (select 'x'
                   from STORET.TSRCHAR    wa
                    where TSRCHAR_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSRCHTYP    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCHTYP'
  and   exists (select 'x'
                   from STORET.TSRCHTYP    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRCPV_IS_NUMBER)
                      from STORET.TSRCPV    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCPV'
  and   exists (select 'x'
                   from STORET.TSRCPV    wa
                    where TSRCPV_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET.TSRCTCA    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCTCA'
  and   exists (select 'x'
                   from STORET.TSRCTCA    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRFLDGR_IS_NUMBER)
                      from STORET.TSRFLDGR    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRFLDGR'
  and   exists (select 'x'
                   from STORET.TSRFLDGR    wa
                    where TSRFLDGR_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRLBRMK_IS_NUMBER)
                      from STORET.TSRLBRMK    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRLBRMK'
  and   exists (select 'x'
                   from STORET.TSRLBRMK    wa
                    where TSRLBRMK_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRUOM_IS_NUMBER)
                      from STORET.TSRUOM    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRUOM'
  and   exists (select 'x'
                   from STORET.TSRUOM    wa
                    where TSRUOM_IS_NUMBER>
                       t1.is_number);

commit;

-- Tables Schema Owner: STORET1 
-- Tables Schema Owner: STORET1 
update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMGNTXT_IS_NUMBER)
                      from STORET1.TSMGNTXT    a
			    where TSMGNTXT_ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMGNTXT'
  and   exists (select 'x'
                   from STORET1.TSMGNTXT    wa
                    where TSMGNTXT_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET1.TSMORGAN    a
			    where ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMORGAN'
  and   exists (select 'x'
                   from STORET1.TSMORGAN    wa
                    where ROWNUM>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSMPROGM_IS_NUMBER)
                      from STORET1.TSMPROGM    a
			    where TSMPROGM_ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMPROGM'
  and   exists (select 'x'
                   from STORET1.TSMPROGM    wa
                    where TSMPROGM_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRANLPR_IS_NUMBER)
                      from STORET1.TSRANLPR    a
			    where TSRANLPR_ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRANLPR'
  and   exists (select 'x'
                   from STORET1.TSRANLPR    wa
                    where TSRANLPR_IS_NUMBER>
                       t1.is_number);


update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRCITN_IS_NUMBER)
                      from STORET1.TSRCITN    a
			    where TSRCITN_ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRCITN'
  and   exists (select 'x'
                   from STORET1.TSRCITN    wa
                    where TSRCITN_IS_NUMBER>
                       t1.is_number);

update STORET1.tsmeisn t1
  set t1.is_number = (select max(TSRLSPP_IS_NUMBER)
                      from STORET1.TSRLSPP    a
			    where TSRLSPP_ORG_ID = 'ZZZZZZZZ'  )
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSRLSPP'
  and   exists (select 'x'
                   from STORET1.TSRLSPP    wa
                    where TSRLSPP_IS_NUMBER>
                       t1.is_number);


-- STORET1 DATA SCHEMA:
Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMADDR' 
;
Insert into storet1.tsmeisn t1
select 'TSMADDR', TSMADDR_ORG_ID, TSMADDR_IS_NUMBER 
From
	(select max(TSMADDR_IS_NUMBER) "TSMADDR_IS_NUMBER", TSMADDR_ORG_ID 
	 from STORET1.TSMADDR group by TSMADDR_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMADDR    wa
                    where TSMADDR_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMALP' 
;
Insert into storet1.tsmeisn t1
select 'TSMALP', TSMALP_ORG_ID, TSMALP_IS_NUMBER 
From
	(select max(TSMALP_IS_NUMBER) "TSMALP_IS_NUMBER", TSMALP_ORG_ID 
	 from STORET1.TSMALP group by TSMALP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMALP    wa
                    where TSMALP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMCPORG' 
;
Insert into storet1.tsmeisn t1
select 'TSMCPORG', TSMCPORG_ORG_ID, TSMCPORG_IS_NUMBER 
From
	(select max(TSMCPORG_IS_NUMBER) "TSMCPORG_IS_NUMBER", TSMCPORG_ORG_ID 
	 from STORET1.TSMCPORG group by TSMCPORG_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMCPORG    wa
                    where TSMCPORG_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMEADDR' 
;
Insert into storet1.tsmeisn t1
select 'TSMEADDR', TSMEADDR_ORG_ID, TSMEADDR_IS_NUMBER 
From
	(select max(TSMEADDR_IS_NUMBER) "TSMEADDR_IS_NUMBER", TSMEADDR_ORG_ID 
	 from STORET1.TSMEADDR group by TSMEADDR_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMEADDR    wa
                    where TSMEADDR_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMERS' 
;
Insert into storet1.tsmeisn t1
select 'TSMERS', TSMERS_ORG_ID, TSMERS_IS_NUMBER 
From
	(select max(TSMERS_IS_NUMBER) "TSMERS_IS_NUMBER", TSMERS_ORG_ID 
	 from STORET1.TSMERS group by TSMERS_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMERS    wa
                    where TSMERS_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMGNTXT' 
;
Insert into storet1.tsmeisn t1
select 'TSMGNTXT', TSMGNTXT_ORG_ID, TSMGNTXT_IS_NUMBER 
From
	(select max(TSMGNTXT_IS_NUMBER) "TSMGNTXT_IS_NUMBER", TSMGNTXT_ORG_ID 
	 from STORET1.TSMGNTXT group by TSMGNTXT_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMGNTXT    wa
                    where TSMGNTXT_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMIGUA' 
;
Insert into storet1.tsmeisn t1
select 'TSMIGUA', TSMIGUA_ORG_ID, TSMIGUA_IS_NUMBER 
From
	(select max(TSMIGUA_IS_NUMBER) "TSMIGUA_IS_NUMBER", TSMIGUA_ORG_ID 
	 from STORET1.TSMIGUA group by TSMIGUA_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMIGUA    wa
                    where TSMIGUA_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMINTVL' 
;
Insert into storet1.tsmeisn t1
select 'TSMINTVL', TSMINTVL_ORG_ID, TSMINTVL_IS_NUMBER 
From
	(select max(TSMINTVL_IS_NUMBER) "TSMINTVL_IS_NUMBER", TSMINTVL_ORG_ID 
	 from STORET1.TSMINTVL group by TSMINTVL_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMINTVL    wa
                    where TSMINTVL_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMLOG' 
;
Insert into storet1.tsmeisn t1
select 'TSMLOG', TSMLOG_ORG_ID, TSMLOG_IS_NUMBER 
From
	(select max(TSMLOG_IS_NUMBER) "TSMLOG_IS_NUMBER", TSMLOG_ORG_ID 
	 from STORET1.TSMLOG group by TSMLOG_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMLOG    wa
                    where TSMLOG_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMPERSN' 
;
Insert into storet1.tsmeisn t1
select 'TSMPERSN', TSMPERSN_ORG_ID, TSMPERSN_IS_NUMBER 
From
	(select max(TSMPERSN_IS_NUMBER) "TSMPERSN_IS_NUMBER", TSMPERSN_ORG_ID 
	 from STORET1.TSMPERSN group by TSMPERSN_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMPERSN    wa
                    where TSMPERSN_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMPIPE' 
;
Insert into storet1.tsmeisn t1
select 'TSMPIPE', TSMPIPE_ORG_ID, TSMPIPE_IS_NUMBER 
From
	(select max(TSMPIPE_IS_NUMBER) "TSMPIPE_IS_NUMBER", TSMPIPE_ORG_ID 
	 from STORET1.TSMPIPE group by TSMPIPE_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMPIPE    wa
                    where TSMPIPE_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMPROGM' 
;
Insert into storet1.tsmeisn t1
select 'TSMPROGM', TSMPROGM_ORG_ID, TSMPROGM_IS_NUMBER 
From
	(select max(TSMPROGM_IS_NUMBER) "TSMPROGM_IS_NUMBER", TSMPROGM_ORG_ID 
	 from STORET1.TSMPROGM group by TSMPROGM_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMPROGM    wa
                    where TSMPROGM_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMPROJ' 
;
Insert into storet1.tsmeisn t1
select 'TSMPROJ', TSMPROJ_ORG_ID, TSMPROJ_IS_NUMBER 
From
	(select max(TSMPROJ_IS_NUMBER) "TSMPROJ_IS_NUMBER", TSMPROJ_ORG_ID 
	 from STORET1.TSMPROJ group by TSMPROJ_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMPROJ    wa
                    where TSMPROJ_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMPUMP' 
;
Insert into storet1.tsmeisn t1
select 'TSMPUMP', TSMPUMP_ORG_ID, TSMPUMP_IS_NUMBER 
From
	(select max(TSMPUMP_IS_NUMBER) "TSMPUMP_IS_NUMBER", TSMPUMP_ORG_ID 
	 from STORET1.TSMPUMP group by TSMPUMP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMPUMP    wa
                    where TSMPUMP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMSTATN' 
;
Insert into storet1.tsmeisn t1
select 'TSMSTATN', TSMSTATN_ORG_ID, TSMSTATN_IS_NUMBER 
From
	(select max(TSMSTATN_IS_NUMBER) "TSMSTATN_IS_NUMBER", TSMSTATN_ORG_ID 
	 from STORET1.TSMSTATN group by TSMSTATN_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMSTATN    wa
                    where TSMSTATN_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMVSC' 
;
Insert into storet1.tsmeisn t1
select 'TSMVSC', TSMVSC_ORG_ID, TSMVSC_IS_NUMBER 
From
	(select max(TSMVSC_IS_NUMBER) "TSMVSC_IS_NUMBER", TSMVSC_ORG_ID 
	 from STORET1.TSMVSC group by TSMVSC_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMVSC    wa
                    where TSMVSC_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMWELL' 
;
Insert into storet1.tsmeisn t1
select 'TSMWELL', TSMWELL_ORG_ID, TSMWELL_IS_NUMBER 
From
	(select max(TSMWELL_IS_NUMBER) "TSMWELL_IS_NUMBER", TSMWELL_ORG_ID 
	 from STORET1.TSMWELL group by TSMWELL_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMWELL    wa
                    where TSMWELL_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRADL' 
;
Insert into storet1.tsmeisn t1
select 'TSRADL', TSRADL_ORG_ID, TSRADL_IS_NUMBER 
From
	(select max(TSRADL_IS_NUMBER) "TSRADL_IS_NUMBER", TSRADL_ORG_ID 
	 from STORET1.TSRADL group by TSRADL_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRADL    wa
                    where TSRADL_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRANLPR' 
;
Insert into storet1.tsmeisn t1
select 'TSRANLPR', TSRANLPR_ORG_ID, TSRANLPR_IS_NUMBER 
From
	(select max(TSRANLPR_IS_NUMBER) "TSRANLPR_IS_NUMBER", TSRANLPR_ORG_ID 
	 from STORET1.TSRANLPR group by TSRANLPR_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRANLPR    wa
                    where TSRANLPR_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRBRG' 
;
Insert into storet1.tsmeisn t1
select 'TSRBRG', TSRBRG_ORG_ID, TSRBRG_IS_NUMBER 
From
	(select max(TSRBRG_IS_NUMBER) "TSRBRG_IS_NUMBER", TSRBRG_ORG_ID 
	 from STORET1.TSRBRG group by TSRBRG_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRBRG    wa
                    where TSRBRG_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRBRGI' 
;
Insert into storet1.tsmeisn t1
select 'TSRBRGI', TSRBRGI_ORG_ID, TSRBRGI_IS_NUMBER 
From
	(select max(TSRBRGI_IS_NUMBER) "TSRBRGI_IS_NUMBER", TSRBRGI_ORG_ID 
	 from STORET1.TSRBRGI group by TSRBRGI_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRBRGI    wa
                    where TSRBRGI_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRCCGA' 
;
Insert into storet1.tsmeisn t1
select 'TSRCCGA', TSRCCGA_ORG_ID, TSRCCGA_IS_NUMBER 
From
	(select max(TSRCCGA_IS_NUMBER) "TSRCCGA_IS_NUMBER", TSRCCGA_ORG_ID 
	 from STORET1.TSRCCGA group by TSRCCGA_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRCCGA    wa
                    where TSRCCGA_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRCHDEF' 
;
Insert into storet1.tsmeisn t1
select 'TSRCHDEF', TSRCHDEF_ORG_ID, TSRCHDEF_IS_NUMBER 
From
	(select max(TSRCHDEF_IS_NUMBER) "TSRCHDEF_IS_NUMBER", TSRCHDEF_ORG_ID 
	 from STORET1.TSRCHDEF group by TSRCHDEF_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRCHDEF    wa
                    where TSRCHDEF_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRCHGRP' 
;
Insert into storet1.tsmeisn t1
select 'TSRCHGRP', TSRCHGRP_ORG_ID, TSRCHGRP_IS_NUMBER 
From
	(select max(TSRCHGRP_IS_NUMBER) "TSRCHGRP_IS_NUMBER", TSRCHGRP_ORG_ID 
	 from STORET1.TSRCHGRP group by TSRCHGRP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRCHGRP    wa
                    where TSRCHGRP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRCITN' 
;
Insert into storet1.tsmeisn t1
select 'TSRCITN', TSRCITN_ORG_ID, TSRCITN_IS_NUMBER 
From
	(select max(TSRCITN_IS_NUMBER) "TSRCITN_IS_NUMBER", TSRCITN_ORG_ID 
	 from STORET1.TSRCITN group by TSRCITN_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRCITN    wa
                    where TSRCITN_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRFDACT' 
;
Insert into storet1.tsmeisn t1
select 'TSRFDACT', TSRFDACT_ORG_ID, TSRFDACT_IS_NUMBER 
From
	(select max(TSRFDACT_IS_NUMBER) "TSRFDACT_IS_NUMBER", TSRFDACT_ORG_ID 
	 from STORET1.TSRFDACT group by TSRFDACT_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRFDACT    wa
                    where TSRFDACT_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRFDSET' 
;
Insert into storet1.tsmeisn t1
select 'TSRFDSET', TSRFDSET_ORG_ID, TSRFDSET_IS_NUMBER 
From
	(select max(TSRFDSET_IS_NUMBER) "TSRFDSET_IS_NUMBER", TSRFDSET_ORG_ID 
	 from STORET1.TSRFDSET group by TSRFDSET_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRFDSET    wa
                    where TSRFDSET_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRFLDPR' 
;
Insert into storet1.tsmeisn t1
select 'TSRFLDPR', TSRFLDPR_ORG_ID, TSRFLDPR_IS_NUMBER 
From
	(select max(TSRFLDPR_IS_NUMBER) "TSRFLDPR_IS_NUMBER", TSRFLDPR_ORG_ID 
	 from STORET1.TSRFLDPR group by TSRFLDPR_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRFLDPR    wa
                    where TSRFLDPR_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRFQS' 
;
Insert into storet1.tsmeisn t1
select 'TSRFQS', TSRFQS_ORG_ID, TSRFQS_IS_NUMBER 
From
	(select max(TSRFQS_IS_NUMBER) "TSRFQS_IS_NUMBER", TSRFQS_ORG_ID 
	 from STORET1.TSRFQS group by TSRFQS_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRFQS    wa
                    where TSRFQS_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRFQSDP' 
;
Insert into storet1.tsmeisn t1
select 'TSRFQSDP', TSRFQSDP_ORG_ID, TSRFQSDP_IS_NUMBER 
From
	(select max(TSRFQSDP_IS_NUMBER) "TSRFQSDP_IS_NUMBER", TSRFQSDP_ORG_ID 
	 from STORET1.TSRFQSDP group by TSRFQSDP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRFQSDP    wa
                    where TSRFQSDP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRGRCFG' 
;
Insert into storet1.tsmeisn t1
select 'TSRGRCFG', TSRGRCFG_ORG_ID, TSRGRCFG_IS_NUMBER 
From
	(select max(TSRGRCFG_IS_NUMBER) "TSRGRCFG_IS_NUMBER", TSRGRCFG_ORG_ID 
	 from STORET1.TSRGRCFG group by TSRGRCFG_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRGRCFG    wa
                    where TSRGRCFG_IS_NUMBER>0);


Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRHCSC' 
;
Insert into storet1.tsmeisn t1
select 'TSRHCSC', TSRHCSC_ORG_ID, TSRHCSC_IS_NUMBER 
From
	(select max(TSRHCSC_IS_NUMBER) "TSRHCSC_IS_NUMBER", TSRHCSC_ORG_ID 
	 from STORET1.TSRHCSC group by TSRHCSC_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRHCSC    wa
                    where TSRHCSC_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRHCSC' 
;
Insert into storet1.tsmeisn t1
select 'TSRHCSC', TSRHCSC_ORG_ID, TSRHCSC_IS_NUMBER 
From
	(select max(TSRHCSC_IS_NUMBER) "TSRHCSC_IS_NUMBER", TSRHCSC_ORG_ID 
	 from STORET1.TSRHCSC group by TSRHCSC_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRHCSC    wa
                    where TSRHCSC_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRLAB' 
;
Insert into storet1.tsmeisn t1
select 'TSRLAB', TSRLAB_ORG_ID, TSRLAB_IS_NUMBER 
From
	(select max(TSRLAB_IS_NUMBER) "TSRLAB_IS_NUMBER", TSRLAB_ORG_ID 
	 from STORET1.TSRLAB group by TSRLAB_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRLAB    wa
                    where TSRLAB_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRLSPP' 
;
Insert into storet1.tsmeisn t1
select 'TSRLSPP', TSRLSPP_ORG_ID, TSRLSPP_IS_NUMBER 
From
	(select max(TSRLSPP_IS_NUMBER) "TSRLSPP_IS_NUMBER", TSRLSPP_ORG_ID 
	 from STORET1.TSRLSPP group by TSRLSPP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRLSPP    wa
                    where TSRLSPP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSROPPRD' 
;
Insert into storet1.tsmeisn t1
select 'TSROPPRD', TSROPPRD_ORG_ID, TSROPPRD_IS_NUMBER 
From
	(select max(TSROPPRD_IS_NUMBER) "TSROPPRD_IS_NUMBER", TSROPPRD_ORG_ID 
	 from STORET1.TSROPPRD group by TSROPPRD_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSROPPRD    wa
                    where TSROPPRD_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRRQCAF' 
;
Insert into storet1.tsmeisn t1
select 'TSRRQCAF', TSRRQCAF_ORG_ID, TSRRQCAF_IS_NUMBER 
From
	(select max(TSRRQCAF_IS_NUMBER) "TSRRQCAF_IS_NUMBER", TSRRQCAF_ORG_ID 
	 from STORET1.TSRRQCAF group by TSRRQCAF_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRRQCAF    wa
                    where TSRRQCAF_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRRSULT' 
;
Insert into storet1.tsmeisn t1
select 'TSRRSULT', TSRRSULT_ORG_ID, TSRRSULT_IS_NUMBER 
From
	(select max(TSRRSULT_IS_NUMBER) "TSRRSULT_IS_NUMBER", TSRRSULT_ORG_ID 
	 from STORET1.TSRRSULT group by TSRRSULT_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRRSULT    wa
                    where TSRRSULT_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRSDP' 
;
Insert into storet1.tsmeisn t1
select 'TSRSDP', TSRSDP_ORG_ID, TSRSDP_IS_NUMBER 
From
	(select max(TSRSDP_IS_NUMBER) "TSRSDP_IS_NUMBER", TSRSDP_ORG_ID 
	 from STORET1.TSRSDP group by TSRSDP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRSDP    wa
                    where TSRSDP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRSTVST' 
;
Insert into storet1.tsmeisn t1
select 'TSRSTVST', TSRSTVST_ORG_ID, TSRSTVST_IS_NUMBER 
From
	(select max(TSRSTVST_IS_NUMBER) "TSRSTVST_IS_NUMBER", TSRSTVST_ORG_ID 
	 from STORET1.TSRSTVST group by TSRSTVST_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRSTVST    wa
                    where TSRSTVST_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSRTRIP' 
;
Insert into storet1.tsmeisn t1
select 'TSRTRIP', TSRTRIP_ORG_ID, TSRTRIP_IS_NUMBER 
From
	(select max(TSRTRIP_IS_NUMBER) "TSRTRIP_IS_NUMBER", TSRTRIP_ORG_ID 
	 from STORET1.TSRTRIP group by TSRTRIP_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSRTRIP    wa
                    where TSRTRIP_IS_NUMBER>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMSOI' 
;
Insert into storet1.tsmeisn t1
select 'TSMSOI', TSMSOI_ORG_ID, TSMSOI_SERIAL_ID, 
From
	(select max(TSMSOI_SERIAL_ID) "TSMSOI_SERIAL_ID", TSMSOI_ORG_ID 
	 from STORET1.TSMSOI group by TSMSOI_ORG_ID) a
Where exists (select 'x'
                   from STORET1.TSMSOI    wa
                    where TSMSOI_SERIAL_ID>0);

Delete 	FROM STORET1.tsmeisn t1
  	WHERE 
	tsmeisn_name = 'TSMORGAN' 
;
Insert into storet1.tsmeisn t1
select 'TSMORGAN', 'ZZZZZZZZ', TSMORGAN_IS_NUMBER 
From
	(select max(TSMORGAN_IS_NUMBER) "TSMORGAN_IS_NUMBER", 'ZZZZZZZZ' 
	 from STORET1.TSMORGAN) a
Where exists (select 'x'
                   from STORET1.TSMORGAN    wa
                    where TSMORGAN_IS_NUMBER>0);



update STORET1.tsmeisn t1
  set t1.is_number = (select max(ROWNUM)
                      from STORET1.TSMEISN    a)
  WHERE TSMEISN_ORG_ID = 'ZZZZZZZZ'
  and   tsmeisn_name = 'TSMEISN'
  and   exists (select 'x'
                   from STORET1.TSMEISN    wa
                    where ROWNUM<
                       t1.is_number);

COMMIT;
set time off
-- Note: 0 rows updated is not an error...
-- Note: 0 rows updated is not an error...
-- Note: 0 rows updated is not an error...
SPOOL OFF
set echo off
set termout on
Prompt Review Log File: ..\EISN_SYNC.LOG
Prompt DONE... Synchronizing Table TSMEISN with Data Tables:STORET,STORET1
-- exit
