-- VISTA SQL Logging - ab 08.12.2017 --
-- 
-- Umlaut-Tracker: ÃƒÆ’Ã‚Â¤ am 30.07.2019
-- 
-- Useful queries --
-- CM --------------------------------------------------------------------------------------------
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('Rolle#IP', 'Rolle#IPV', 'Rolle#VB')
order by c.value;

select p.kpvpartid, a.kpvadrsid
from vista.tpvpartner p
join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
where a.validto > current date and a.kpvadrsid is null;

/*
CODE_ID         SHORTCODE   VALUE  LONG_DESCRIPT                                                        
--------------  ----------  -----  -------------------------------------------------------------------  
Civil stat#U    U                  Unbekannt                                                            
Civil stat#L    L           1      Ledig                                                                
Civil stat#H    H           2      Verheiratet                                                          
Civil stat#W    W           3      Verwitwet                                                            
Civil stat#S    S           4      Geschieden                                                           
*/
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'Civil stat#%'
order by c.value;
/*
CODE_ID         SHORTCODE   VALUE  LONG_DESCRIPT                                                        
--------------  ----------  -----  -------------------------------------------------------------------  
Civil stat#U    U           0      Unbekannt                                                            
Civil stat#L    L           1      Ledig                                                                
Civil stat#H    H           2      Verheiratet                                                          
Civil stat#W    W           3      Verwitwet                                                            
Civil stat#S    S           4      Geschieden                                                           
Civil stat#G    G           5      Gerichtlich getrennt                                                 
Civil stat#GPS  GPS         6      Eingetragene Partnerschaft gleichgeschlechtlicher Partner            
Civil stat#GGP  GGP         7      Gerichtlich aufgelÃƒÆ’Ã‚Â¶ste Partnerschaft gleichgeschlechtlicher Partner  
Civil stat#GTP  GTP         8      Durch Tod aufgelÃƒÆ’Ã‚Â¶ste Partnerschaft gleichgeschlechtlicher Partner    
Civil stat#GRP  GRP         9      Richterlich getrennte Partnerschaft gleichgeschlechtlicher Partner   
*/
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'LegalAgent#%'
order by c.value;

select * from vista.tiscmcodetype where company_shortcode='PV'; -- shortcode = 1034706
select * from vista.tiscmcode where codetypeno=1034706;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'BORD%'
order by c.value;
/*
CODE_ID     SHORTCODE   VALUE  LONG_DESCRIPT           
----------  ----------  -----  ----------------------  
BORDTYPE#1  1                  PDF                     
BORDTYPE#2  2                  EXCEL                   
BORDTYPE#3  3                  TXT-TFS                 
BORDTYPE#4  4                  PDF und EXCEL           
BORDTYPE#5  5                  PDF und TXT-TFS         
BORDTYPE#6  6                  EXCEL und TXT-TFS       
BORDTYPE#7  7                  PDF, EXCEL und TXT-TFS  
*/

select * from vista.tpvpartner where cseparation is not null;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Sex%'
order by c.value;
/*
CODE_ID  SHORTCODE   VALUE  LONG_DESCRIPT  
-------  ----------  -----  -------------  
Sex#M    M                  MÃƒÂ¤nnlich       
Sex#U    U                  Unbekannt      
Sex#W    W                  Weiblich                                                               
*/
select c.code_id, c.shortcode, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Separ%'
order by c.value;

select c.code_id, c.shortcode, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'CorresLang%'
order by c.value;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'ERFASSTCOD%'
order by c.value;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'BSVLAND%'
order by shortcode; -- d.long_descript; -- Hong Kong fehlt in IK... ?

select c.code_id, c.shortcode, c.value, d.medium_descript, c.VALID_FROM, c.valid_to from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=3)
where c.code_id like 'Country%'
and c.valid_to < '9999-12-31'
order by d.medium_descript; -- Hong Kong fehlt in IK... ?

select c.code_id, c.shortcode, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('Country#RS', 'Country#XZ')
order by d.medium_descript; -- AN / XZ

select c.code_id, c.shortcode, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('Country#SU', 'Country#SD')
order by d.medium_descript; -- AN / XZ

select c.code_id, c.shortcode, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('Country#LI', 'Country#CH')
order by d.medium_descript; -- CH: 100 / LI: 222 - in LI umgekehrt!

select c.code_id, c.shortcode, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.value is null
order by d.medium_descript;

select /*c.code_id,*/ c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'PVCONST%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=2)
where c.code_id like 'PVCONST%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'ZAMSGTYPE#%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'ForeignPay%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'TypePaymen%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'CompoundFu#%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=2)
where c.code_id like 'KEPROLE%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=2)
where c.code_id like 'KEPCONF%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'CSSWITCHES%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'NNPersonTy%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Correspond#IP%' or c.code_id like 'Correspond#VB%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Rolle#IP%' or c.code_id like 'Rolle#VB%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'FLG%'
order by c.shortcode;

select c.code_id, c.shortcode, c.const_field, c.value, d.short_descript, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'MQOUTINFO%'
order by c.shortcode;



select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='IBANDetail') and c.shortcode='DE'
order by c.value;
/*
CODE_ID        SHORTCODE   LONG_DESCRIPT  ATTR_SHORTCODE  ATTR_VALUE  
-------------  ----------  -------------  --------------  ----------  
IBANDetail#EG  EG          Ägypten        AutoLookup      N           
IBANDetail#EG  EG          Ägypten        BCNoLength      0           
IBANDetail#EG  EG          Ägypten        CntrySupp       Y           
IBANDetail#EG  EG          Ägypten        Length          27          
*/
select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='IBANDetail') and attr.shortcode='isSEPA' and attr.value='Y'
order by c.shortcode;
/*
CODE_ID        SHORTCODE   LONG_DESCRIPT          ATTR_SHORTCODE  ATTR_VALUE  
-------------  ----------  ---------------------  --------------  ----------  
IBANDetail#AD  AD          Andorra                isSEPA          Y           
IBANDetail#AT  AT          Östereich              isSEPA          Y           
IBANDetail#BE  BE          Belgien                isSEPA          Y           
IBANDetail#BG  BG          Bulgarien              isSEPA          Y           
IBANDetail#CH  CH          Schweiz                isSEPA          Y           
(...)
*/

select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='Country') and c.shortcode='CH'
order by c.value;
/*
CODE_ID     SHORTCODE   LONG_DESCRIPT  ATTR_SHORTCODE  ATTR_VALUE  
----------  ----------  -------------  --------------  ----------  
Country#CH  CH          Schweiz        BSVNummer       100         
Country#CH  CH          Schweiz        ISO3166A3       CHE         
Country#CH  CH          Schweiz        IstEULand       false       
Country#CH  CH          Schweiz        IstEFTALan      true        
Country#CH  CH          Schweiz        DatBilAbko      01.06.2002  
Country#CH  CH          Schweiz        KKraftIdx       100         
*/

-- Messages
select * from vista.tiscmcode where company_shortcode='PV' and code_id like 'MSGTYPE%'; -- codetypeno=1000132 / codeno=1020759
select * from vista.tiscmcodetype_lang where codetypeno=1000132; -- Meldungstypen

select * from vista.tiscmcode_descr where codetypeno=1000132 and codeno=1020759 and language=4;

select code.shortcode, lang.long_descript from vista.tiscmcode code
left join vista.tiscmcode_descr lang on (lang.codetypeno = code.codetypeno and lang.codeno = code.codeno and language = 4)
where code.shortcode='PV00809080';
-- Nur IK, nur Italienisch:
select code.shortcode, lang.long_descript from vista.tiscmcode code
left join vista.tiscmcode_descr lang on (lang.codetypeno = code.codetypeno and lang.codeno = code.codeno and language = 3)
where code_id like 'MSGTYPE#%' and company_shortcode='IK';

-- KEP:
select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='KEPCONF')
order by c.value;
/*
CODE_ID             SHORTCODE   LONG_DESCRIPT           ATTR_SHORTCODE  ATTR_VALUE  
------------------  ----------  ----------------------  --------------  ----------  
KEPCONF#VN          VN                                  KPADshow        Y           
KEPCONF#VN          VN                                  KPGTshow        Y           
KEPCONF#VN          VN                                  KPSPshow        Y           
KEPCONF#VN          VN                                  KPFRshow        Y           
KEPCONF#VN          VN                                  KPTDshow        Y           
KEPCONF#VN          VN                                  AttrFetch       Y           
KEPCONF#NATIONID    NATIONID                            AttrFetch       Y           
KEPCONF#NATIONID    NATIONID                            AttrCompar      Y           
(...)
*/

-- DEFLANG --------------------------------------------------------------------------------------------
-- default language / default Sprache in CM: (NOT: "RECONSTCAN#AKDEFLANG")
select * from vista.tiscmcode where code_id = 'VISTAADMIN#DEFLANG';

-- GILAI / web@AI -------------------------------------------------------------------------------------
select * from vista.aaireplication;
select * from vista.aaipartner; -- ccitizenship
select * from vista.aaiaddress; -- ccountry

-- OS / DOPE ------------------------------------------------------------------------------------------
-- UPI ------------------------------------------------------------------------------------------------
select distinct new_nnss from vista.aurupiregister upi where not exists (
    select 1 from vista.tpvpartner p where p.personid = upi.new_nnss
) and not exists (
    select 1 from vista.tikheader h where h.vnr = upi.new_nnss
) and statuscd='0' and actualitycd='1';

select * from vista.aurupiregister upi where statuscd in ('2', '3');
select * from vista.aurupiregister upi where statuscd='3' and actualitycd='1'; -- empty

-- DB2 -------------------------------------------------------------------------------------------------
-- Find all tables by table names:
select * from sysibm.systables where name like 'TIK%' and type = 'T'; -- 50 TIK-Tables
select * from sysibm.systables where name like 'TPV%' and type = 'T'; -- 31 TPV-Tables

-- Find all columns by name:
select * from syscat.columns where tabschema='VISTA' and colname like '%DOCREF%';

-- Table IDs:
SELECT C.TABSCHEMA, C.TABNAME, C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = 303
AND T.TABLEID = 3
AND C.COLNO = 2
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME;
/*
TABSCHEMA  TABNAME     COLNAME    
---------  ----------  ---------  
VISTA      TPVADDRESS  KPVPARTID
*/

-- DB / Federated DB - UPI ------------------------------------------
select current server as db, servername, create_time, option, setting
from syscat.serveroptions
where option in ( 'DBNAME' , 'NODE' )
order by option;
/*
DB        SERVERNAME     CREATE_TIME          OPTION  SETTING   
--------  -------------  -------------------  ------  --------  
VIDPDBGR  ZASDBSERVER    2020-10-21 10:19:55  DBNAME  vidpdbza  
VIDPDBGR  GILAIDBSERVER  2020-08-08 12:26:55  DBNAME  vidpdbex  
VIDPDBGR  ZASDBSERVER    2020-10-21 10:19:55  NODE    vidpinza  
VIDPDBGR  GILAIDBSERVER  2020-08-08 12:26:54  NODE    vidpingr  
*/

-- MQ ------------------------------------------------------------------------------------------------------------------------------------------------------
select * from vista.tsfmqoutbound where lastupdated>'2021-06-10 08:00:30' and jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqinbound where lastupdated>'2021-06-10 08:00:30' and jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqinbound where lastupdated>'2021-06-10 08:00:30' and jmstype='EA-N001' order by lastupdated desc;
select * from vista.tsfmqevent where lastupdated>'2021-06-10 08:00:30' order by lastupdated desc;
select tsfmqoutboundid, reason, jmscorrelationid,  substr(outboundmsg, (position('<messageID>', outboundmsg, OCTETS) + 11), 36) as messageId
from vista.tsfmqoutbound where reason is not null and lastupdated>'2017-11-09 12:40:30' and jmstype='BZ.PV-I003' order by lastupdated desc;

--- XML-Parsing ---------
-- Replication-XMLtable:
with outboundtable as (
	select out.tsfmqoutboundid, x.triggeringObject, x.triggeringObjectKey, out.reason
	from vista.tsfmqoutbound out,
	XMLtable ('$d/*:PartnerReplicationRequestEnvelopeType/*:body' passing XMLparse(document outboundmsg) as "d"
		columns
			triggeringObject varchar(20) path './*:triggeringObject',
			triggeringObjectKey bigint path './*:triggeringObjectKey'
		) as x
	where out.jmstype='BZ.PV-I003' and out.lastupdated > '2021-05-21'
)
select * from outboundtable where triggeringObjectKey=2498426;
--------------

select tsfmqoutboundid, reason, jmscorrelationid,  substr(
    outboundmsg, (position('<messageID>', outboundmsg, OCTETS) + 11), --36
    
) as messageId
from vista.tsfmqoutbound where reason is not null and lastupdated>'2017-11-09 12:40:30' and jmstype='BZ.PV-I003' order by lastupdated desc;


select tsfmqoutboundid, reason, jmscorrelationid,  

cast ( SUBSTR( 
    OUTBOUNDMSG, LOCATE_IN_STRING(OUTBOUNDMSG, '<messageID>') + 11,
    (LOCATE_IN_STRING(OUTBOUNDMSG, '</messageID>') - LOCATE_IN_STRING(OUTBOUNDMSG, '<messageID>') - 11) -- length
) as varchar(36) ) as x_message_id
,
cast ( SUBSTR( 
    OUTBOUNDMSG, LOCATE_IN_STRING(OUTBOUNDMSG, '<ns3:lzPartnerKey>') + 18,
    (LOCATE_IN_STRING(OUTBOUNDMSG, '</ns3:lzPartnerKey>') - LOCATE_IN_STRING(OUTBOUNDMSG, '<ns3:lzPartnerKey>') - 18) -- length
) as varchar(21) ) as x_kpvpartid
from vista.tsfmqoutbound where 
-- reason is not null and OUTBOUNDMSG is not null and lastupdated>'2017-12-01 12:40:30' and jmstype='BZ.PV-I003' order by lastupdated desc;
tsfmqoutboundid = 1372233130;
-- (not working in case partnerKey not provided)

select tsfmqoutboundid, reason, jmscorrelationid,  
cast ( SUBSTR( 
    OUTBOUNDMSG, LOCATE_IN_STRING(OUTBOUNDMSG, '<messageID>') + 11,
    (LOCATE_IN_STRING(OUTBOUNDMSG, '</messageID>') - LOCATE_IN_STRING(OUTBOUNDMSG, '<messageID>') - 11) -- length
) as varchar(36) ) as x_message_id
,
cast ( SUBSTR( 
    OUTBOUNDMSG, LOCATE_IN_STRING(OUTBOUNDMSG, '<ns2:triggeringObject>') + 22,
    (LOCATE_IN_STRING(OUTBOUNDMSG, '</ns2:triggeringObject>') - LOCATE_IN_STRING(OUTBOUNDMSG, '<ns2:triggeringObject>') - 22) -- length
) as varchar(21) ) as x_triggering_object
,
cast ( SUBSTR( 
    OUTBOUNDMSG, LOCATE_IN_STRING(OUTBOUNDMSG, '<ns2:triggeringObjectKey>') + 25,
    (LOCATE_IN_STRING(OUTBOUNDMSG, '</ns2:triggeringObjectKey>') - LOCATE_IN_STRING(OUTBOUNDMSG, '<ns2:triggeringObjectKey>') - 25) -- length
) as varchar(21) ) as x_triggering_object_key
from vista.tsfmqoutbound where 
reason is not null and OUTBOUNDMSG is not null and OUTBOUNDMSG not like '%<ns3:lzPartnerKey>%' and lastupdated>'2017-12-01 12:40:30' and jmstype='BZ.PV-I003' order by lastupdated desc;
--tsfmqoutboundid = 1372233130;
select * from vista.tsfmqoutbound where tsfmqoutboundid = 1369991179;

select * from vista.jpvpartner where kpvpartid=308579786; -- partner deleted
select * from vista.jpvpaymentaddr where kpvpaddid=1299192588; -- payment addr deleted --> partner:
select * from vista.tpvpartner where kpvpartid=5640794;

select tsfmqoutboundid, reason, jmscorrelationid, outboundmsg
from vista.tsfmqoutbound where 
reason is not null and OUTBOUNDMSG is not null and OUTBOUNDMSG not like '%<ns3:lzPartnerKey>%' and lastupdated>'2017-12-01 12:40:30' and jmstype='BZ.PV-I003' order by lastupdated desc;

select * from vista.tsfmqoutbound where lastupdated>'2017-12-01 12:40:30' and jmstype='BZ.PV-I003' and reason is not null order by lastupdated desc;
select tsfmqoutboundid, reason, jmscorrelationid, lastupdated, outboundmsg
from vista.tsfmqoutbound where lastupdated>'2017-12-01 12:40:30' and jmstype='BZ.PV-I003' and reason is not null order by lastupdated desc;
select * from vista.tsfmqevent;

-- 15'000 Events wegen BaseNameType length = 0
select tsfmqoutboundid, reason, jmscorrelationid, lastupdated, outboundmsg
from vista.tsfmqoutbound where lastupdated>'2017-12-05 14:00:00' and lastupdated<'2017-12-05 17:00:00' and jmstype='BZ.PV-I003' and reason='MQOUTBREJ#INVOUTXML' 
--and outboundmsg like '%<zasName>%'
order by lastupdated desc;

select kpvpartid, name, change_date, change_user, program, operation
from vista.jpvpartner where change_date>'2017-12-05 14:00:00' and change_date<'2017-12-05 17:00:00'; 

-- Inbound / User
select * from vista.tsfmqinbound where jmstype='LZ.PV-RR001' order by lastupdated desc;
select * from vista.tsfmqoutbound where jmstype='LZ.PV-RR001' order by lastupdated desc;

-- Inbound Minipartner
select * from vista.tsfmqinbound where jmstype='LZ.PV-I002' order by lastupdated desc;
select * from vista.tsfmqinbound where jmstype='BZ.BW-I003' order by lastupdated desc;
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tpvpartner where kpvpartid=999991013000001;


-- Post file -----------------------------------------------------------------------------------------------------------------------------------------------
select * from vista.abdpostfilestreet;
/*
TBDPOSTFILESTREETID  STREET                ZIP4  ZIPADDON  ZIP6    SHORTCITY        COUNTRY  ADDRSCANTON  STREETNR  STREETNRADDON  POLGNAME         POLGCANTON  BFSNR  LASTUPDATED          
-------------------  --------------------  ----  --------  ------  ---------------  -------  -----------  --------  -------------  ---------------  ----------  -----  -------------------  
391                  Allmendstrasse        8914  00        891400  Aeugst am Albis  CH       ZH           10        (null)         Aeugst am Albis  ZH          1      2017-09-14 16:00:41  
392                  Allmendstrasse        8914  00        891400  Aeugst am Albis  CH       ZH           12        (null)         Aeugst am Albis  ZH          1      2017-09-14 16:00:41  
393                  Allmendstrasse        8914  00        891400  Aeugst am Albis  CH       ZH           13        (null)         Aeugst am Albis  ZH          1      2017-09-14 16:00:41  
*/
select * from vista.abdpostfilezip;
/*
TBDPOSTFILEZIPID  ZIP4  ZIPADDON  ZIP6    CITY                         SHORTCITY           COUNTRY  BFSNR  POLGNAME              CANTON  LASTUPDATED          
----------------  ----  --------  ------  ---------------------------  ------------------  -------  -----  --------------------  ------  -------------------  
1                 8914  00        891400  Aeugst am Albis              Aeugst am Albis     CH       1      Aeugst am Albis       ZH      2017-09-14 16:00:14  
2                 8914  02        891402  Aeugstertal                  Aeugstertal         CH       1      Aeugst am Albis       ZH      2017-09-14 16:00:14  
3                 8909  00        890900  Zwillikon                    Zwillikon           CH       2      Affoltern am Albis    ZH      2017-09-14 16:00:14  
*/
select count(*) from vista.tbdpostfilezip;
select count(*) from vista.abdpostfilestreet;

select * from vista.abdpostfilestreet where street='Postfach';

-- DKA ------------------------------------------------------------------------------------------------
select * from dka.tdkrequest order by exec_ts_start desc; -- order by tdkrequest.exec_ts_start desc;





-- 163913 - ZH - Quellensteuer nicht in EDV2000
select * from vista.tpvpartner where name='Rizzo' and firstname='Antonio' and kpvpartid=11034254; -- isvic = N

-- PVJREPLI
select count(*) from vista.tpvpartner p where exists (
 select 1 from vista.tpvaddress a where a.kpvpartid = p.kpvpartid and a.validto > p.validto
);

-- Regionen
select * from vista.tpvregion order by name;
/*
TPVREGIONID  KPVREGIONID  NAME       VALIDFROM   VALIDTO     LASTUPDATED          
-----------  -----------  ---------  ----------  ----------  -------------------  
68775017     68775018     REGION#01  1900-01-01  9999-12-31  2010-09-22 10:32:27  
68775009     68775010     REGION#02  1900-01-01  9999-12-31  2010-09-22 10:32:27  
68775013     68775014     REGION#03  1900-01-01  9999-12-31  2010-09-22 10:32:27  
68775005     68775006     REGION#04  1900-01-01  9999-12-31  2010-09-22 10:32:27  
567529076    567529077    REGION#05  1900-01-01  9999-12-31  2013-12-05 11:09:31  
*/
select * from vista.tpvregionmunauth;

-- 163209 - ZH - Gemeindefusionen (Hofstetten-Elgg)
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (222, 271, 294) or ahvbranchnr in (93 , 88)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID   KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                 ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ---------  ---------------------  -------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
963520      963521     25553713               Gemeinde Elgg        (null)          NNPersonTy#POLG  88           (null)       FLGAllocat#T   217             1900-01-01  2009-12-31  2017-09-13 08:19:11  
215641405   963521     25553713               Gemeinde Elgg        (null)          NNPersonTy#POLG  88           (null)       FLGAllocat#T   217             2010-01-01  2017-12-31  2017-12-12 09:32:59  
3092742143  963521     25553713               Gemeinde Elgg        (null)          NNPersonTy#POLG  88           (null)       FLGAllocat#T   294             2018-01-01  9999-12-31  2017-12-12 09:32:59  
215648486   963789     25166686               Gemeinde Hofstetten  (null)          NNPersonTy#POLG  93           (null)       FLGAllocat#T   222             2010-01-01  9999-12-31  2011-08-12 12:29:22  
963784      963789     25166686               Gemeinde Hofstetten  (null)          NNPersonTy#POLG  93           (null)       FLGAllocat#T   222             1900-01-01  2009-12-31  2017-09-13 08:42:37  
*/

WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where ahvbranchnr in (93, 88) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME             ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ---------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
25166682   25166686   (null)                 AHV-Zweigstelle  Hofstetten      NNPersonTy#AHVZ  (null)       93           (null)         (null)          1900-01-01  9999-12-31  2011-08-10 08:45:52  
25553711   25553713   (null)                 AHV-Zweigstelle  Elgg            NNPersonTy#AHVZ  (null)       88           (null)         (null)          1900-01-01  9999-12-31  2011-08-10 09:07:29  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (25166686) or 
    a.kpvpartid_munauthor in (963789) or 
    t.kpvpartid_taxdomicile in (963789) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;

-- Achtung, DB-Changes (extPartnerKey)
select * from vista.tpvaddress;
declare global temporary table tmp_tpvaddress (
    tpvadrsid BIGINT, kpvpartid BIGINT, kpvpartid_munauthor BIGINT, kpvadbaid BIGINT, kpvadrsid BIGINT,
    caddresstype VARCHAR(21), appendix1 VARCHAR(40), appendix2 VARCHAR(40), cappendixpos VARCHAR(21),
    streetnr VARCHAR(40), upperstreetnr VARCHAR(40), sector VARCHAR(40), locked CHAR(1), cstructure VARCHAR(21),
    cbusinessapp VARCHAR(21), validfrom DATE, validto DATE, extpartnerkey VARCHAR(36), lastupdated TIMESTAMP
) 
on commit preserve rows not logged;

insert into session.tmp_tpvaddress (
    tpvadrsid, kpvpartid, kpvpartid_munauthor, kpvadbaid, kpvadrsid, caddresstype, 
    appendix1, appendix2, cappendixpos, streetnr, 
    upperstreetnr, sector, locked, cstructure, cbusinessapp, validfrom, validto, extaddresskey, lastupdated
)
select * from vista.tpvaddress a
where a.kpvpartid_munauthor in (963789) and a.validfrom < '2018-01-01' and a.validto='9999-12-31';

select * from vista.tpvpartner;




-- 166114 - ZH - Gemeindefusion - Hirzel-Horgen
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (132, 133) or ahvbranchnr in (28, 29)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID   KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME             ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ---------  ---------------------  ---------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
963377      963378     25782478               Gemeinde Horgen  (null)          NNPersonTy#POLG  29           (null)       FLGAllocat#T   133             1900-01-01  2009-12-31  2011-08-12 11:21:34  
215648781   963378     25782478               Gemeinde Horgen  (null)          NNPersonTy#POLG  29           (null)       FLGAllocat#T   133             2010-01-01  2017-12-31  2017-12-13 10:28:55  
3094911846  963378     25782478               Gemeinde Horgen  (null)          NNPersonTy#POLG  29           (null)       FLGAllocat#T   295             2018-01-01  9999-12-31  2017-12-13 10:28:55  
215646830   964570     26333656               Gemeinde Hirzel  (null)          NNPersonTy#POLG  28           (null)       FLGAllocat#T   132             2010-01-01  9999-12-31  2011-08-12 12:28:27  
964569      964570     26333656               Gemeinde Hirzel  (null)          NNPersonTy#POLG  28           (null)       FLGAllocat#T   132             1900-01-01  2009-12-31  2017-09-13 08:41:09  
*/
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where ahvbranchnr in (28, 29) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME             ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ---------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
25782470   25782478   (null)                 AHV-Zweigstelle  Horgen          NNPersonTy#AHVZ  (null)       29           (null)         (null)          1900-01-01  9999-12-31  2011-02-21 16:56:07  
26333655   26333656   (null)                 AHV-Zweigstelle  Hirzel          NNPersonTy#AHVZ  (null)       28           (null)         (null)          1900-01-01  9999-12-31  2011-02-21 16:53:06  
*/

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (26333656) or 
    a.kpvpartid_munauthor in (964570) or 
    t.kpvpartid_taxdomicile in (964570) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31' -- and p.validto='2017-12-31'
order by p.kpvpartid;


select * from vista.tpvaddress a where a.kpvpartid_munauthor in (26333656) and a.validfrom < '2018-01-01' and a.validto='9999-12-31'; -- empty (falsch)
select * from vista.tpvaddress a where a.kpvpartid_munauthor in (964570) and a.validfrom < '2018-01-01' and a.validto='9999-12-31';


-- 166613 - SO - MIT-Rolle terminieren
-- AIT301
select * from vista.tpvpartner order by lastupdated desc; -- working case: 42805
select * from vista.tpvrole where kpvpartid=42805;


-- Duplicate Minipartner
-- AIT: 7562528797983
select * from vista.aurupiregister where new_nnss='7562528797983'; -- okupi
select * from vista.tpvpartner where personid='7562528797983'; -- empty
select upi.new_nnss from vista.aurupiregister upi where not exists (
    select 1 from vista.tpvpartner p where p.personid = upi.new_nnss
);

-- GR - Gemeindefusionen 2018
-- 1) Thusis
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (3503, 3668) or ahvbranchnr in (602, 690)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME              ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ----------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
959489     959490     30595571               Gemeinde Mutten   (null)          NNPersonTy#POLG  602          (null)       FLGAllocat#T   3503            1900-01-01  2017-12-31  2017-12-20 17:00:12  
572729049  959490     30595571               *Gemeinde Mutten  (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#T   (null)          2018-01-01  9999-12-31  2017-12-20 17:01:07  
961180     961181     30595361               Gemeinde Thusis   (null)          NNPersonTy#POLG  690          (null)       FLGAllocat#T   3668            1900-01-01  9999-12-31  2013-07-29 17:29:54  
*/
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where ahvbranchnr in (602, 690) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                     ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  -----------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
30595360   30595361   (null)                 AHV-Zweigstelle Thusis   (null)          NNPersonTy#AHVZ  (null)       690          (null)         (null)          1900-01-01  9999-12-31  2012-10-11 11:51:10  
30595570   30595571   (null)                 AHV-Zweigstelle Mutten   (null)          NNPersonTy#AHVZ  (null)       602          (null)         (null)          1900-01-01  2017-12-31  2017-12-20 17:50:03  
572732028  30595571   (null)                 *AHV-Zweigstelle Mutten  (null)          NNPersonTy#AHVZ  (null)       602          (null)         (null)          2018-01-01  9999-12-31  2017-12-20 17:50:03  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (30595571) or 
    a.kpvpartid_munauthor in (959490) or 
    t.kpvpartid_taxdomicile in (959490) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;
-- 100 --> 32 nicht mutiert!
-- AHVZ:
drop table session.tmp_tpvpartner;
declare global temporary table tmp_tpvpartner (
    tpvpartid BIGINT, kpvpartid BIGINT, kpvpartid_court BIGINT, kpvpartid_redundanz BIGINT, kpvpartid_munautor BIGINT, kpvpartid_heirrepresent BIGINT, 
    kpvpartid_bequeather BIGINT, kpvpartid_taxdomicile BIGINT, kpvpartid_ahvbranchnr BIGINT, kpvpartid_officeoperationnr BIGINT, kpvpartid_bankruptcy BIGINT, cpartnertype VARCHAR(21), 
    socialsecnr VARCHAR(40), titel VARCHAR(40), name VARCHAR(80), namesx CHAR(4), uppername VARCHAR(80), firstname VARCHAR(40), firstnamesx CHAR(4), upperfirstname VARCHAR(40), 
    lastname VARCHAR(80), upperlastname VARCHAR(80), birthname VARCHAR(80), upperbirthname VARCHAR(80), cnamesequence VARCHAR(21), clanguage VARCHAR(21), birthdate DATE, 
    birthdateprec BIGINT, ccivilstatus VARCHAR(21), civilstatussince DATE, cconfidlevel VARCHAR(21), clegaltype VARCHAR(21), clegalform VARCHAR(21), csex VARCHAR(21), 
    additionalname VARCHAR(80), upperadditionalname VARCHAR(80), ccanton VARCHAR(21), companynr VARCHAR(40), ahvbranchnr BIGINT, cahvchiefsalut VARCHAR(21), 
    ahvchieffirstname VARCHAR(40), ahvchiefname VARCHAR(40), ahvchiefsince DATE, cahvdeputysalut VARCHAR(21), ahvdeputyfirstname VARCHAR(40), ahvdeputyname VARCHAR(40), 
    ahvdeputysince DATE, compfundnr BIGINT, compfundbranchnr BIGINT, compfundcede CHAR, ccompfundtype VARCHAR(21), ccompfundfaktype VARCHAR(21), compfundfusionnr BIGINT, 
    compfundfubranr BIGINT, officeoperationnr BIGINT, ivofficenr BIGINT, kkabsvnr BIGINT, munauthornr BIGINT, cmunauthorcanton VARCHAR(21), cmunauthorflg VARCHAR(21), 
    cinsurancetype VARCHAR(21), insurancesuvanr BIGINT, agencynumber VARCHAR(12), ccitizenship VARCHAR(21), citizenshipsince DATE, personid VARCHAR(40), cseparation VARCHAR(21), separationdate DATE, 
    ccountryofliving VARCHAR(21), countryoflivingsince DATE, cresidauthor VARCHAR(21), residauthorsince DATE, deathdate DATE, ctaxcountry VARCHAR(21), ctaxcanton VARCHAR(21), 
    taxregnr VARCHAR(80), ctaxatsource VARCHAR(21), bfsmunitipalnr VARCHAR(20), ccourttype VARCHAR(21), cclerkalloc VARCHAR(21), remarks VARCHAR(80), temp CHAR, isvic CHAR, validfrom DATE, validto DATE, 
    temp9999 CHAR, extpartnerkey VARCHAR(36), lastupdated TIMESTAMP
) 
on commit preserve rows not logged;
insert into session.tmp_tpvpartner (
    tpvpartid, kpvpartid, kpvpartid_court, kpvpartid_redundanz, kpvpartid_munautor, kpvpartid_heirrepresent, kpvpartid_bequeather, kpvpartid_taxdomicile, kpvpartid_ahvbranchnr, 
    kpvpartid_officeoperationnr, kpvpartid_bankruptcy, cpartnertype, socialsecnr, titel, name, namesx, uppername, firstname, firstnamesx, upperfirstname, lastname, upperlastname, birthname, upperbirthname, 
    cnamesequence, clanguage, birthdate, birthdateprec, ccivilstatus, civilstatussince, cconfidlevel, clegaltype, clegalform, csex, additionalname, upperadditionalname, ccanton, 
    companynr, ahvbranchnr, cahvchiefsalut, ahvchieffirstname, ahvchiefname, ahvchiefsince, cahvdeputysalut, ahvdeputyfirstname, ahvdeputyname, ahvdeputysince, compfundnr, 
    compfundbranchnr, compfundcede, ccompfundtype, ccompfundfaktype, compfundfusionnr, compfundfubranr, officeoperationnr, ivofficenr, kkabsvnr, munauthornr, cmunauthorcanton, 
    cmunauthorflg, cinsurancetype, insurancesuvanr, agencynumber, ccitizenship, citizenshipsince, personid, cseparation, separationdate, ccountryofliving, countryoflivingsince, cresidauthor, 
    residauthorsince, deathdate, ctaxcountry, ctaxcanton, taxregnr, ctaxatsource, bfsmunitipalnr, ccourttype, cclerkalloc, remarks, temp, isvic, validfrom, validto, temp9999, extpartnerkey, lastupdated
)
select * from vista.tpvpartner p
where p.kpvpartid_ahvbranchnr in (30595571) and p.validfrom < '2018-01-01' and p.validto='9999-12-31' and p.cpartnertype='PartnerTyp#NP';
-- cclerkalloc / agencynumber / ccourttype / kpvpartid_bankruptcy
update session.tmp_tpvpartner set kpvpartid_ahvbranchnr = 30595361, validfrom = '2018-01-01', validto = '9999-12-31', lastupdated = current timestamp; -- 31 updates
insert into vista.tpvpartner (
    tpvpartid, kpvpartid, kpvpartid_court, kpvpartid_redundanz, kpvpartid_munautor, kpvpartid_heirrepresent, kpvpartid_bequeather, kpvpartid_taxdomicile, kpvpartid_ahvbranchnr, 
    kpvpartid_officeoperationnr, kpvpartid_bankruptcy, cpartnertype, socialsecnr, titel, name, namesx, uppername, firstname, firstnamesx, upperfirstname, lastname, upperlastname, birthname, upperbirthname, 
    cnamesequence, clanguage, birthdate, birthdateprec, ccivilstatus, civilstatussince, cconfidlevel, clegaltype, clegalform, csex, additionalname, upperadditionalname, ccanton, 
    companynr, ahvbranchnr, cahvchiefsalut, ahvchieffirstname, ahvchiefname, ahvchiefsince, cahvdeputysalut, ahvdeputyfirstname, ahvdeputyname, ahvdeputysince, compfundnr, 
    compfundbranchnr, compfundcede, ccompfundtype, ccompfundfaktype, compfundfusionnr, compfundfubranr, officeoperationnr, ivofficenr, kkabsvnr, munauthornr, cmunauthorcanton, 
    cmunauthorflg, cinsurancetype, insurancesuvanr, agencynumber, ccitizenship, citizenshipsince, personid, cseparation, separationdate, ccountryofliving, countryoflivingsince, cresidauthor, 
    residauthorsince, deathdate, ctaxcountry, ctaxcanton, taxregnr, ctaxatsource, bfsmunitipalnr, ccourttype, cclerkalloc, remarks, temp, isvic, validfrom, validto, temp9999, extpartnerkey, lastupdated
)
select 
    next value for vista.vista_seq, kpvpartid, kpvpartid_court, kpvpartid_redundanz, kpvpartid_munautor, kpvpartid_heirrepresent, kpvpartid_bequeather, kpvpartid_taxdomicile, kpvpartid_ahvbranchnr, 
    kpvpartid_officeoperationnr, kpvpartid_bankruptcy, cpartnertype, socialsecnr, titel, name, namesx, uppername, firstname, firstnamesx, upperfirstname, lastname, upperlastname, birthname, upperbirthname, 
    cnamesequence, clanguage, birthdate, birthdateprec, ccivilstatus, civilstatussince, cconfidlevel, clegaltype, clegalform, csex, additionalname, upperadditionalname, ccanton, 
    companynr, ahvbranchnr, cahvchiefsalut, ahvchieffirstname, ahvchiefname, ahvchiefsince, cahvdeputysalut, ahvdeputyfirstname, ahvdeputyname, ahvdeputysince, compfundnr, 
    compfundbranchnr, compfundcede, ccompfundtype, ccompfundfaktype, compfundfusionnr, compfundfubranr, officeoperationnr, ivofficenr, kkabsvnr, munauthornr, cmunauthorcanton, 
    cmunauthorflg, cinsurancetype, insurancesuvanr, agencynumber, ccitizenship, citizenshipsince, personid, cseparation, separationdate, ccountryofliving, countryoflivingsince, cresidauthor, 
    residauthorsince, deathdate, ctaxcountry, ctaxcanton, taxregnr, ctaxatsource, bfsmunitipalnr, ccourttype, cclerkalloc, remarks, temp, isvic, validfrom, validto, temp9999, extpartnerkey, lastupdated
from session.tmp_tpvpartner s;







-- 2) Berguen:
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (3521, 3522, 3544) or ahvbranchnr in (512, 549, 745)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
-- Neuer Partner EDU:

WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where ahvbranchnr in (512, 549, 745) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;

-- EDU:
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (37477639, 37477454) or 
    a.kpvpartid_munauthor in (959235, 959318) or 
    t.kpvpartid_taxdomicile in (959235, 959318) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;
-- 455 -- 764! // Neu EDU: 1516 // Neuer EDU: 1079 // noch neuer EDU: 691
-- Test konkreter Fall:
-- 756.8845.8144.33
select * from vista.tpvtaxdata where kpvpartid in (select distinct kpvpartid from vista.tpvpartner where personid='7568845814433');
-- Test konkreter Fall
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, p.lastupdated
from vista.tpvpartner p
where (
    p.personid='7562733145739' 
)
and p.cpartnertype='PartnerTyp#NP' -- and p.validto = '9999-12-31'
order by p.kpvpartid;
-- Falsche AHVZ-Links auf Partner durch erste Version vom Script
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, p.lastupdated
from vista.tpvpartner p
where p.kpvpartid_ahvbranchnr = 37477454 and p.validfrom = '2018-01-01' -- falsche AHVZ: 37477454, richtig wÃƒÂ¤re: 573891164
and p.cpartnertype='PartnerTyp#NP' -- and p.validto = '9999-12-31'
order by p.kpvpartid;

-- Prod:
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (37477639, 37477454) or 
    a.kpvpartid_munauthor in (959235, 959318) or 
    t.kpvpartid_taxdomicile in (959235, 959318) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid; -- 898

-- BI-Probleme?
select * from vista.tbiprocessed_uow where vista_kpv_key in (
    select distinct kpvpartid from vista.tpvpartner where lastupdated >= '2018-01-15' and kpvpartid_ahvbranchnr = 582225883 and validfrom = '2018-01-01'
); -- Alles auf P



-- 3) Brigels
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (3611, 3616, 3981) or ahvbranchnr in (505, 716, 518)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                         ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ---------------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
960928     960929     31265264               Gemeinde Breil/Brigels       (null)          NNPersonTy#POLG  518          (null)       FLGAllocat#T   3981            1900-01-01  9999-12-31  2013-07-29 16:59:42  
960981     960983     31264795               Gemeinde Waltensburg/Vuorz   (null)          NNPersonTy#POLG  716          (null)       FLGAllocat#T   3616            1900-01-01  2017-12-31  2017-12-21 15:24:41  
572831062  960983     31264795               *Gemeinde Waltensburg/Vuorz  (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#T   (null)          2018-01-01  9999-12-31  2017-12-21 15:24:41  
961162     961163     31264868               Gemeinde Andiast             (null)          NNPersonTy#POLG  505          (null)       FLGAllocat#T   3611            1900-01-01  2017-12-31  2017-12-21 15:20:15  
572830742  961163     31264868               *Gemeinde Andiast            (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#T   (null)          2018-01-01  9999-12-31  2017-12-21 15:20:15  
*/
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where ahvbranchnr in (505, 716, 518) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                           ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  -----------------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
31264794   31264795   (null)                 AHV-Zweigstelle Waltensburg    (null)          NNPersonTy#AHVZ  (null)       716          (null)         (null)          1900-01-01  2017-12-31  2017-12-21 15:25:04  
572831064  31264795   (null)                 *AHV-Zweigstelle Waltensburg   (null)          NNPersonTy#AHVZ  (null)       716          (null)         (null)          2018-01-01  9999-12-31  2017-12-21 15:25:04  
31264867   31264868   (null)                 AHV-Zweigstelle Andiast        (null)          NNPersonTy#AHVZ  (null)       505          (null)         (null)          1900-01-01  2017-12-31  2017-12-21 15:21:20  
572830744  31264868   (null)                 *AHV-Zweigstelle Andiast       (null)          NNPersonTy#AHVZ  (null)       505          (null)         (null)          2018-01-01  9999-12-31  2017-12-21 15:21:20  
31265263   31265264   (null)                 AHV-Zweigstelle Breil/Brigels  (null)          NNPersonTy#AHVZ  (null)       518          (null)         (null)          1900-01-01  9999-12-31  2012-10-02 17:44:48  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (31264795, 31264868) or 
    a.kpvpartid_munauthor in (960983, 961163) or 
    t.kpvpartid_taxdomicile in (960983, 961163) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;
-- 569 (edu) / 598 (prod)
-- Fehlerliste:
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (31264795, 31264868) or 
    a.kpvpartid_munauthor in (960983, 961163) or 
    t.kpvpartid_taxdomicile in (960983, 961163) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;
--
select count(*) from vista.tpvaddress where kpvpartid_munauthor in (960983, 961163) and validto > '2017-12-31'; -- 0
select count(*) from vista.tpvtaxdata where kpvpartid_taxdomicile in (960983, 961163) and validto > '2017-12-31'; -- 4
select * from vista.tpvpartner where kpvpartid_ahvbranchnr in (31264795, 31264868) and validto > '2017-12-31'; -- 244
select count(*) from vista.tpvpartner where kpvpartid_ahvbranchnr in (31265264) and validto > '2017-12-31'; -- 406
select j.kpvpartid, j.tpvpartid, j.kpvpartid_ahvbranchnr, j.name, j.validfrom, j.validto, j.change_date, j.change_user, j.program, j.operation from vista.jpvpartner_archive_cc0493 j
where j.kpvpartid in (
    select p.kpvpartid from vista.tpvpartner p where p.kpvpartid_ahvbranchnr in (31264795, 31264868) and p.validto > '2017-12-31'
);

-- DKA - AHVZ-Nr. lÃƒÆ’Ã‚Â¶schen
select * from vista.tpvpartner where name in ('*AHV-Zweigstelle Filisur', '*AHV-Zweigstelle Mutten', '*AHV-Zweigstelle Andiast', '*AHV-Zweigstelle Waltensburg');
select * from vista.tpvpartner where name like '%AHV-Zweigstelle Waltensburg%';
update vista.tpvpartner set ahvbranchnr = null, lastupdated = current timestamp
where name in ('*AHV-Zweigstelle Filisur', '*AHV-Zweigstelle Mutten', '*AHV-Zweigstelle Andiast', '*AHV-Zweigstelle Waltensburg');


-- 165938 - SO - IPV2010 Adnovum: Korrespondenzadresse kann nicht geladen werden
select * from vista.tpvrolerel where TPVRRELID=396354098; -- kpvrrelid=396354099
select * from vista.tpvrolerel where kpvrrelid=396354099;
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT          MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  -------------------------  ------------------  -----------  -------------------  
396354098  177105333         4681802           (null)     396354099  6879418         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2015-11-02  9999-12-31  Correspond#VBV      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
*/
select * from vista.tpvaddress where kpvadrsid=6879418;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1             APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
---------  ---------  -------------------  ---------  ---------  -------------  --------------------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
6879416    4681792    (null)               47757      6879418    AddressTyp#ZA  Charlotte Stadelmann  (null)     AppendixPo#V  630       630            (null)  N       AddressStr#CH  (null)        1996-01-01  1996-01-02  (null)         2016-12-21 08:28:25  
*/
select * from vista.tpvrolerel where TPVRRELID=497390116;
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT          MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  -------------------------  ------------------  -----------  -------------------  
497390116  177105333         4681802           (null)     497390117  6879418         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2016-11-04  9999-12-31  Correspond#VBV      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
*/
select * from vista.tpvaddress where kpvadrsid=6879418;
select * from vista.tpvrole where kpvroleid=177105333; -- VB
select name, firstname, personid from vista.tpvpartner where kpvpartid=2340295;
/*
NAME  FIRSTNAME  PERSONID       
----  ---------  -------------  
Hess  Devika     7561337689472  
*/
select * from vista.tpvrolerel where kpvroleid_source=177105333;
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT          MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  -------------------------  ------------------  -----------  -------------------  
177105381  177105333         4681802           (null)     177105384  132869699       (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2013-01-17  9999-12-31  Correspond#VBV      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
177105414  177105333         4681802           (null)     177105415  132869699       (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2013-01-17  9999-12-31  Correspond#VBA      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
177373341  177105333         4751266           7141271    177373342  (null)          (null)          (null)                RoleRelati#ZE  (null)           PaymentAdd#VBV     (null)         (null)               2013-01-18  9999-12-31  (null)              (null)                     (null)              (null)       2013-01-18 20:49:14  
177373391  177105333         4681802           (null)     177373392  132869699       (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2013-01-18  9999-12-31  Correspond#VBK      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
186600048  177105333         4716247           7080840    186600049  (null)          (null)          (null)                RoleRelati#ZE  (null)           PaymentAdd#VBV     (null)         (null)               2013-03-07  9999-12-31  (null)              (null)                     (null)              (null)       2013-03-07 10:27:00  
236173958  177105333         4716247           7224142    236173959  (null)          (null)          (null)                RoleRelati#ZE  (null)           PaymentAdd#VBV     (null)         (null)               2013-12-09  9999-12-31  (null)              (null)                     (null)              (null)       2013-12-09 21:38:37  
257136313  177105333         19420334          19420417   257136314  (null)          (null)          (null)                RoleRelati#ZE  (null)           PaymentAdd#VBV     (null)         (null)               2014-02-25  9999-12-31  (null)              (null)                     (null)              (null)       2014-02-25 20:47:29  
396354098  177105333         4681802           (null)     396354099  6879418         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2015-11-02  9999-12-31  Correspond#VBV      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
497390116  177105333         4681802           (null)     497390117  6879418         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2016-11-04  9999-12-31  Correspond#VBV      Guten Tag Frau Stadelmann                      (null)       2017-11-08 08:07:36  
*/
select p.kpvpartid, p.name, p.firstname, p.personid, a.caddresstype, a.appendix1, ab.street, a.streetnr, ab.zip, ab.city, a.validfrom, a.validto from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid=p.kpvpartid)
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where a.kpvadrsid=6879418;
/*
KPVPARTID  NAME                    FIRSTNAME  PERSONID  CADDRESSTYPE   APPENDIX1             STREET    STREETNR  ZIP     CITY       VALIDFROM   VALIDTO     
---------  ----------------------  ---------  --------  -------------  --------------------  --------  --------  ------  ---------  ----------  ----------  
4681792    Pro Infirmis Solothurn  (null)     (null)    AddressTyp#ZA  Charlotte Stadelmann  Postfach  630       450100  Solothurn  1996-01-01  1996-01-02  
4681792    Pro Infirmis Solothurn  (null)     (null)    AddressTyp#ZA  Charlotte Stadelmann  Postfach  630       450100  Solothurn  1996-01-01  1996-01-02  
*/


-- IBANisierung, AS-Workload, Mail Andrea 04.01.2018
select * from vista.tpvpartnerreplication
where date(creationtime) >= '02.01.2018'
and ctargetappl = 'BusinessAp#AS'
and kpvpartid in (1034539,1034567);
/*
TPVPARTREPID  KPVPARTID  VALIDFROM   CTARGETAPPL    CSTATUS             CREATIONRUN  CREATIONTIME         REPLICATIONRUN  REPLICATIONTIME      LASTUPDATED          
------------  ---------  ----------  -------------  ------------------  -----------  -------------------  --------------  -------------------  -------------------  
3057613777    1034539    2018-01-02  BusinessAp#AS  RepState#PROCESSED  3057594225   2018-01-02 10:06:46  3057729151      2018-01-03 01:35:16  2018-01-03 01:35:16  
3057609681    1034567    2011-01-01  BusinessAp#AS  RepState#PROCESSED  3057594225   2018-01-02 10:06:09  3057729151      2018-01-02 23:35:52  2018-01-02 23:35:52  
3057616014    1034567    2018-01-02  BusinessAp#AS  RepState#PROCESSED  3057594225   2018-01-02 10:07:05  3057729151      2018-01-03 02:41:52  2018-01-03 02:41:52  
*/
with x as (
select kpvpartid, count(*) as cnt_repli from vista.tpvpartnerreplication
where date(creationtime) >= '02.01.2018'
and ctargetappl = 'BusinessAp#AS'
group by kpvpartid
order by count(*) desc
)
select cnt_repli, count(*) as cnt_x from x
group by cnt_repli;

with x as (
select kpvpartid, count(*) as cnt_repli from vista.tpvpartnerreplication
where date(creationtime) = '02.01.2018'
and ctargetappl = 'BusinessAp#AS'
group by kpvpartid
order by count(*) desc
)
select cnt_repli, count(*) as cnt_x from x
group by cnt_repli;

-- Partner 1:
select * from vista.jpvpartner where kpvpartid=1034567; -- leer, d.h. kein Update auf Partner
select kpvpartid, tpvpartid, validfrom, validto from vista.tpvpartner where kpvpartid=1034567;
select * from vista.jpvaddress where kpvpartid=1034567; -- leer, d.h. kein Update auf Adresse
select * from vista.tpvpaymentaddr where kpvpartid=1034567;
/*
TPVPADDID   KPVPARTID  KPVPADDID  KPVBANKID  CPAYTYPE      ACCOUNT     IBAN                   CCOUNTRY    ACCOUNTHOLDER  VALIDFROM   VALIDTO     KPVADRSID  SAPNR  EXTACCOUNTKEY  LASTUPDATED          
----------  ---------  ---------  ---------  ------------  ----------  ---------------------  ----------  -------------  ----------  ----------  ---------  -----  -------------  -------------------  
234892029   1034567    234892030  26376157   TypePaymen#P  17-81334-0  (null)                 Country#CH  (null)         2011-01-01  2018-01-01  (null)     1      (null)         2018-01-02 10:00:37  
3057566718  1034567    234892030  26376157   TypePaymen#I  (null)      CH3909000000170813340  (null)      (null)         2018-01-02  9999-12-31  (null)     1      (null)         2018-01-02 10:00:37  
*/
select * from vista.jpvpaymentaddr where kpvpartid=1034567; -- siehe oben

-- Partner 2:
select * from vista.jpvpartner where kpvpartid=1034539; -- leer, d.h. kein Update auf Partner
select * from vista.jpvaddress where kpvpartid=1034539; -- leer, d.h. kein Update auf Adresse
select * from vista.tpvpaymentaddr where kpvpartid=1034539;
/*
TPVPADDID   KPVPARTID  KPVPADDID  KPVBANKID  CPAYTYPE      ACCOUNT     IBAN                   CCOUNTRY    ACCOUNTHOLDER  VALIDFROM   VALIDTO     KPVADRSID  SAPNR  EXTACCOUNTKEY  LASTUPDATED          
----------  ---------  ---------  ---------  ------------  ----------  ---------------------  ----------  -------------  ----------  ----------  ---------  -----  -------------  -------------------  
245901676   1034539    245901677  26376157   TypePaymen#P  34-15790-5  (null)                 Country#CH  (null)         2011-01-01  2018-01-01  (null)     1      (null)         2018-01-02 10:00:36  
3057566702  1034539    245901677  26376157   TypePaymen#I  (null)      CH4309000000340157905  (null)      (null)         2018-01-02  9999-12-31  (null)     1      (null)         2018-01-02 10:00:36  
*/

-- Mutierte Banken?
select * from vista.jpvbankbasic where date(change_date) >= '2018-01-02'; -- empty
select * from vista.jpvaddressbasic where date(change_date) >= '2018-01-02'; -- empty

-- Code:
select KPVPARTID as ID, VALIDFROM, 0 as recid, CHANGE_DATE, 'JPVPAYMENTADDR'  as SOURCE  from vista.JPVPAYMENTADDR 
where CHANGE_DATE > '2018-01-02 10:00:36' and OPERATION <> 'D' and VALIDTO > current date
order by id;


-- AS-Rollen
select count(distinct kpvroleid) from vista.tpvrole where croletype='Rolle#AS'; -- ZH: 6850
select count(distinct kpvroleid) from vista.tpvrole where croletype='Rolle#RE'; -- ZH: 271518
select * from vista.tasdocument; -- empty
select * from vista.tascompensation; -- empty
select * from vista.tasremission; -- 236
select count(*) from vista.tasclearingagreement; -- 11411
select * from vista.tasinsolvency; -- empty

--
select * from vista.tpvdynamicparams;
insert into vista.tpvdynamicparams values (next value for vista.VISTA_SEQ, 'PVJRVAL_START', current timestamp, null, current timestamp);


-- 167934 - SZ - Neue Bank "Raiffeisen Schweiz" erfassen
select * from vista.tpvbankbasic where clearingnr='80808'; -- 434894472
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME            ADDRESS1         ADDRESS2  ZIP     CITY        BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ------------------  ---------------  --------  ------  ----------  --------  ----------  ----------  ----------  -------------------  
434894471  434894472  (null)   80808       Raiffeisen Schweiz  Raiffeisenplatz  (null)    900000  St. Gallen  0         Country#CH  2018-01-01  9999-12-31  2018-01-11 11:22:16  
3071499    3071500    (null)   80808       Raiffeisenbank      Postfach 628     (null)    386000  Meiringen   0         Country#CH  2001-01-01  2009-04-14  2009-06-03 22:08:23  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=434894472; -- empty
select * from vista.tbikeymapping2000 where vista_kpv_key=3071500;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
6488244      3071499        3071500        2001-01-01        2009-04-14      TPVBANKBASIC      0                         TFIRMA              45595315903114   2009-04-14 08:19:09  2009-06-04 00:29:26  
*/


-- Duplicate Minipartner - MQ CreateMinipartner - AIT301
select * from vista.tsfmqinbound where lastupdated>'2018-01-15 12:00:00'; -- and jmstype='BZ.PV-I003' order by lastupdated desc;
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                         JMSREPLYTO  BUSINESSPROCESSID                     TENANTID  TOPIC                         USERNAME  USERLANGUAGECODE  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -------------------------------------  ----------  ------------------------------------  --------  ----------------------------  --------  ----------------  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
58107           0       (null)  JMSTextMessage   LZ.PV-I002  2                0              4            ID:414d51205453533135303341202020207b0b5c5a258b6202  1516019078239  67a1fe3c-2f71-4593-87a0-204f96233f43  queue:///LZPV.I002.MINIPARTNER.CREATE  (null)      aaeb54e7-c0f1-48c1-994f-b4396d035269  ZH        LZPV/I002/MiniPartner/Create  ZHLOGIN   en                <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns4:IGS-CreateMinipartnerRequest xmlns:ns5="https://igs-gmbh.ch/xmlns/igs-0007/1" xmlns="https://igs-gmbh.ch/xmlns/igs-0040/1" xmlns:ns2="http://igs-gmbh.ch/xmlns/igs-PV/lzbz/lzbz-9002" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0006/1" xmlns:ns4="https://igs-gmbh.ch/xmlns/igs-0042/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://igs-gmbh.ch/xmlns/igs-0042/1 ../xsd/igs-0042.xsd">	<ns3:head>		<ns3:senderId>LZ</ns3:senderId>		<ns3:initiatedSenderId>LZ</ns3:initiatedSenderId>		<ns3:messageID>947434d6-7b99-4dc7-9baa-9a1b6b45fcfc</ns3:messageID>		<ns3:message>			<ns3:type>igs-0042</ns3:type>			<ns3:version>1</ns3:version>		</ns3:message>		<ns3:sendingApplication>			<ns3:sendingProduct>LZ-PV</ns3:sendingProduct>			<ns3:sendingProductVersion>V.12.42.002</ns3:sendingProductVersion>		</ns3:sendingApplication>		<ns3:messageDate>2016-12-09T11:35:42.453+01:00</ns3:messageDate>		<ns3:initialMessageDate>2016-12-09T11:35:42.453+01:00</ns3:initialMessageDate>		<ns3:eventDate>2016-12-09T11:35:42.453+01:00</ns3:eventDate>		<ns3:tenant>SG</ns3:tenant>		<ns3:languageCode>en</ns3:languageCode>	</ns3:head>	<ns4:body>			<ns4:nnss>7562528797983</ns4:nnss>			<ns4:bzPartnerKey>95787132-7e2a-4059-b64d-9a918c3be14b</ns4:bzPartnerKey>	</ns4:body></ns4:IGS-CreateMinipartnerRequest>  2018-01-15 13:24:39  
*/
select tpvpartid, kpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where lastupdated>'2018-01-15 12:00:00';
/*
TPVPARTID  KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE   SOCIALSECNR  TITEL   NAME      NAMESX  UPPERNAME  FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE   BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE  CLEGALFORM  CSEX   ADDITIONALNAME  UPPERADDITIONALNAME  CCANTON  COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID       CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS  TEMP  ISVIC   VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          
---------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  -------------  -----------  ------  --------  ------  ---------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ----------  -------------  ------------  ----------------  ------------  ----------  ----------  -----  --------------  -------------------  -------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  -------------  -----------  --------------  ----------------  --------------------  ------------  ----------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  -------  ----  ------  ----------  ----------  --------  -------------  -------------------  
58111      58112      (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  (null)       (null)  Zuend_ik  Z532    ZUEND_IK   Elisabeth  E421         ELISABETH       Zuend_ik  ZUEND_IK       (null)     (null)          NameHyphen#Y   CorresLang#D  1948-03-23  0              (null)        (null)            Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#CH    (null)            7562528797983  (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       (null)   N     (null)  1948-03-23  9999-12-31  (null)    (null)         2018-01-15 13:24:40  
*/
select tpvpartid, kpvpartid, name, firstname, personid, validfrom, validto, change_date, change_user, operation, program from vista.jpvpartner 
where change_date>'2018-01-15 12:00:00' and operation = 'I';
-- UPI-Entries without PV partners
select distinct new_nnss from vista.aurupiregister upi where not exists (
    select 1 from vista.tpvpartner p where p.personid = upi.new_nnss
) and statuscd='0' and actualitycd='1'; -- 182 entries on AIT
-- 1st record 7560000425101 has a wrong check digit!
-- 2nd entry 7560342361656 has multiple valid entries!
-- 5th entry 7560636695315 has wrong check digit!
--
-- Partner created by IK: 7560358060840
select * from vista.tpvpartner where lastupdated>'2018-01-15 12:00:00';

-- Weder in IK noch in PV
select distinct new_nnss from vista.aurupiregister upi where not exists (
    select 1 from vista.tpvpartner p where p.personid = upi.new_nnss
) and not exists (
    select 1 from vista.tikheader h where h.vnr = upi.new_nnss
) and statuscd='0' and actualitycd='1'; -- 169 entries on AIT




-- SIT35 - NullPointerException in Replication MQ (16.01.2018, Testcenter Winterthur)
select * from vista.tpvpartner where personid='7569161582198'; -- 4987542, lastupdated: 2018-01-16 15:29:19
select * from vista.tsfmqevent where key2=4987542;
/*
TSFMQEVENTID  CREATED              PRIORITY  STATUS  APPLICATION  TRIGGEROBJECT  ACTION  KEY1       KEY2     LASTUPDATED          
------------  -------------------  --------  ------  -----------  -------------  ------  ---------  -------  -------------------  
1394954140    2018-01-16 15:29:19  4         1       PV           PARTNER        U       733396795  4987542  2018-01-16 15:30:59  
*/
select * from vista.tsfmqoutbound where lastupdated > '2018-01-16 15:30:00' and lastupdated < '2018-01-16 15:40:00' and jmstype='BZ.PV-I003' and outboundmsg like '%4987542%';
-- 3 Entries, lastupdated = 2018-01-16 15:30:59
--> Replikation bis Systemgrenze ok. Fehler in B&Z? ZivilstÃƒÂ¤nde?

-- NullPointer 
/*
java.lang.NullPointerException at com.ibm.vista.pv.asl.provider.realizer.PvNaturalPersonASPRealizer.loadReplicationPartner(PvNaturalPersonASPRealizer.java:2535) 
at com.ibm.vista.pv.asl.provider.impl.PvNaturalPersonASP.loadReplicationPartner(PvNaturalPersonASP.java:1816) 
at com.ibm.vista.pv.mq.BZPVI003.V1.PvReplicationMsgBean.processMqMessage(PvReplicationMsgBean.java:209) 
at com.ibm.vista.common.mq.ejb.DefaultMessageHandlerBean.executeApplicationTransaction(DefaultMessageHandlerBean.java:525)
*/
select * from vista.tsfmqevent where created > '2018-01-16 16:35:00' and created < '2018-01-16 16:45:00';
/*
TSFMQEVENTID  CREATED              PRIORITY  STATUS  APPLICATION  TRIGGEROBJECT  ACTION  KEY1        KEY2        LASTUPDATED          
------------  -------------------  --------  ------  -----------  -------------  ------  ----------  ----------  -------------------  
1394966110    2018-01-16 16:39:00  4         1       PV           ROLE           D       1386315770  1386315769  2018-01-16 16:40:49  
1394966113    2018-01-16 16:39:00  4         1       PV           ROLE           I       1394966111  1394966112  2018-01-16 16:40:49  
*/
select * from vista.jpvrole where kpvroleid=1386315769;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                 OPERATION  
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ----------------------  ---------  
1386315770  1386315769  841635201  Rolle#AG   (null)     (null)       N       2015-03-01  9999-12-31  2018-01-10 15:41:05  2018-01-10 15:41:05  DB2ADM       CLP importBZRollen.sql  I          
1386315770  1386315769  841635201  Rolle#AG   (null)     (null)       N       2015-03-01  9999-12-31  2018-01-10 15:41:05  2018-01-16 16:39:00  sgsit185     PV:LZ.PV-I001-V1        D          
*/
select tpvroleid, kpvroleid, kpvpartid, croletype, active, validfrom, validto, change_date, change_user, program, operation 
from vista.jpvrole where kpvpartid=841635201 and croletype='Rolle#AG' order by change_date desc;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  ACTIVE  VALIDFROM   VALIDTO     CHANGE_DATE          CHANGE_USER  PROGRAM                 OPERATION  
----------  ----------  ---------  ---------  ------  ----------  ----------  -------------------  -----------  ----------------------  ---------  
1394966111  1394966112  841635201  Rolle#AG   Y       2017-01-01  9999-12-31  2018-01-16 16:39:00  sgsit185     PV:LZ.PV-I001-V1        I          
1386315770  1386315769  841635201  Rolle#AG   N       2015-03-01  9999-12-31  2018-01-16 16:39:00  sgsit185     PV:LZ.PV-I001-V1        D          
1386315770  1386315769  841635201  Rolle#AG   N       2015-03-01  9999-12-31  2018-01-10 15:41:05  DB2ADM       CLP importBZRollen.sql  I          
*/


select * from vista.tpvrole where kpvpartid=841635201;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
841635202   841635203   841635201  Rolle#STA  (null)     (null)       (null)  2015-07-27  9999-12-31  2015-07-27 13:55:44  
1394966111  1394966112  841635201  Rolle#AG   (null)     (null)       Y       2017-01-01  9999-12-31  2018-01-16 16:39:00  
*/
select * from vista.jpvrole where kpvroleid=1394966112;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM           OPERATION  
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ----------------  ---------  
1394966111  1394966112  841635201  Rolle#AG   (null)     (null)       Y       2017-01-01  9999-12-31  2018-01-16 16:39:00  2018-01-16 16:39:00  sgsit185     PV:LZ.PV-I001-V1  I          
*/

select tpvpartid, kpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid=841635201;
/*
TPVPARTID  KPVPARTID  NAME                           FIRSTNAME  PERSONID  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -----------------------------  ---------  --------  ----------  ----------  -------------------  
841635200  841635201  MalergeschÃƒÂ¤ft Waldburger GmbH  (null)     (null)    2015-07-27  9999-12-31  2015-07-27 13:55:44  
*/
select * from vista.tsfmqinbound where lastupdated > '2018-01-16 16:35:00' and lastupdated < '2018-01-16 16:45:00' and jmstype='LZ.PV-I001'; -- and outboundmsg like '%4987542%';
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                       JMSREPLYTO  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------  ----------  ------------------------------------  --------  ------  --------  ----------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
1394966105      0       (null)  JMSTextMessage   LZ.PV-I001  2                0              4            ID:414d5120414258313433355320202020e9d5595a219ed799  1516117139848  7eeacf4f-4e97-4d0a-8016-fb5f4e3e5062  queue:///BZBW.LZPV.I001.ROLE.UPDATE  (null)      e6e91268-fccc-4ff7-a11a-b2729097b0e2  SG        (null)  sgsit185  de                <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-CreateUpdateRoleRequest xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0043/1" xmlns="https://igs-gmbh.ch/xmlns/igs-0006/1" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/1">
    <head>
        <senderId>BZ-PV</senderId>
        <initiatedSenderId>BZ-PV</initiatedSenderId>
        <messageID>007fe7b5-98b6-4d1e-81e4-e0e02c40ccbf</messageID>
        <businessProcessID>e6e91268-fccc-4ff7-a11a-b2729097b0e2</businessProcessID>
        <message>
            <type>igs-0043</type>
            <version>1</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.28.0</sendingProductVersion>
        </sendingApplication>
        <messageDate>2018-01-16T16:39:00.000+01:00</messageDate>
        <initialMessageDate>2018-01-16T16:39:00.000+01:00</initialMessageDate>
        <eventDate>2018-01-16T16:39:00.000+01:00</eventDate>
        <tenant>SG</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:lzPartnerKey>841635201</ns2:lzPartnerKey>
        <ns2:bzPartnerKey>8ded6dfa-c882-4b3c-9f08-31313b9c5b8f</ns2:bzPartnerKey>
        <ns2:roleType>AG</ns2:roleType>
        <ns2:historizedRoleData>
            <ns2:active>1</ns2:active>
            <ns2:validFrom>2017-01-01</ns2:validFrom>
            <ns2:validTill>9999-12-31</ns2:validTill>
        </ns2:historizedRoleData>
    </ns2:body>
</ns2:IGS-CreateUpdateRoleRequest>  2018-01-16 16:39:00  
*/


-- Strassenverzeichnis Validierung - Change-Vorschlag
select * from vista.tbdpostfilestreet;


-- Post-2-IBAN
select cpaytype, count(*) from vista.tpvpaymentaddr
group by cpaytype;


-- 163993 - ZG - Rechtsform ndern (Massenupdate)
select * from vista.tpvpartner where kpvpartid=1910471;

select * from vista.tpvpartner where cpartnertype='PartnerTyp#NNP'; -- 30506 (Paintball-City)
select * from vista.tpvpartner where kpvpartid=30506 and cpartnertype='PartnerTyp#NNP';

insert into vista.tpvpartner (
    tpvpartid, kpvpartid, kpvpartid_court, kpvpartid_redundanz, kpvpartid_munautor, kpvpartid_heirrepresent, kpvpartid_bequeather, kpvpartid_taxdomicile, kpvpartid_ahvbranchnr, 
    kpvpartid_officeoperationnr, kpvpartid_bankruptcy, cpartnertype, socialsecnr, titel, name, namesx, uppername, firstname, firstnamesx, upperfirstname, lastname, upperlastname, birthname, upperbirthname, 
    cnamesequence, clanguage, birthdate, birthdateprec, ccivilstatus, civilstatussince, cconfidlevel, clegaltype, clegalform, csex, additionalname, upperadditionalname, ccanton, 
    companynr, ahvbranchnr, cahvchiefsalut, ahvchieffirstname, ahvchiefname, ahvchiefsince, cahvdeputysalut, ahvdeputyfirstname, ahvdeputyname, ahvdeputysince, compfundnr, 
    compfundbranchnr, compfundcede, ccompfundtype, ccompfundfaktype, compfundfusionnr, compfundfubranr, officeoperationnr, ivofficenr, kkabsvnr, munauthornr, cmunauthorcanton, 
    cmunauthorflg, cinsurancetype, insurancesuvanr, agencynumber, ccitizenship, citizenshipsince, personid, cseparation, separationdate, ccountryofliving, countryoflivingsince, cresidauthor, 
    residauthorsince, deathdate, ctaxcountry, ctaxcanton, taxregnr, ctaxatsource, bfsmunitipalnr, ccourttype, cclerkalloc, remarks, temp, isvic, validfrom, validto, temp9999, extpartnerkey, lastupdated
)
select 
    next value for vista.vista_seq, kpvpartid, kpvpartid_court, kpvpartid_redundanz, kpvpartid_munautor, kpvpartid_heirrepresent, kpvpartid_bequeather, kpvpartid_taxdomicile, kpvpartid_ahvbranchnr, 
    kpvpartid_officeoperationnr, kpvpartid_bankruptcy, cpartnertype, socialsecnr, titel, name, namesx, uppername, firstname, firstnamesx, upperfirstname, lastname, upperlastname, birthname, upperbirthname, 
    cnamesequence, clanguage, birthdate, birthdateprec, ccivilstatus, civilstatussince, cconfidlevel, clegaltype, 'LegalFormC#GMBH', csex, additionalname, upperadditionalname, ccanton, 
    companynr, ahvbranchnr, cahvchiefsalut, ahvchieffirstname, ahvchiefname, ahvchiefsince, cahvdeputysalut, ahvdeputyfirstname, ahvdeputyname, ahvdeputysince, compfundnr, 
    compfundbranchnr, compfundcede, ccompfundtype, ccompfundfaktype, compfundfusionnr, compfundfubranr, officeoperationnr, ivofficenr, kkabsvnr, munauthornr, cmunauthorcanton, 
    cmunauthorflg, cinsurancetype, insurancesuvanr, agencynumber, ccitizenship, citizenshipsince, personid, cseparation, separationdate, ccountryofliving, countryoflivingsince, cresidauthor, 
    residauthorsince, deathdate, ctaxcountry, ctaxcanton, taxregnr, ctaxatsource, bfsmunitipalnr, ccourttype, cclerkalloc, remarks, temp, isvic, '2018-01-01', '9999-12-31', temp9999, extpartnerkey, current timestamp
from vista.tpvpartner p
where p.kpvpartid=30506 and p.validfrom<'2018-01-01' and p.validto='9999-12-31';

update vista.tpvpartner p set validto='2017-12-31', lastupdated=current timestamp
where p.kpvpartid=30506 and p.validfrom<'2018-01-01' and p.validto='9999-12-31';

-- MIG BE AS, SAP

-- birthdateprec
select * from vista.tpvpartner where birthdateprec = 1;
select a.kpvadrsid, ab.zip, ab.city, ab.ccountry, a.cstructure from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid) where a.cstructure <> 'AddressStr#CH'; -- AddressStr#CH


select count(distinct kpvpartid) as cnt_no_nnss from vista.tpvpartner p1 where p1.cpartnertype='PartnerTyp#NP' and p1.socialsecnr is not null
and not exists (
    select 1 from vista.tpvpartner p2 where p2.kpvpartid = p1.kpvpartid and p2.personid is not null
); -- SG: 918; ZH: 147'142 (!)

select kpvpartid, lastupdated , char( lastupdated) from vista.tpvaddress
where kpvpartid = 1437038191;

select current timestamp , GENERATE_UNIQUE(), char(TIMESTAMP(GENERATE_UNIQUE()) + CURRENT TIMEZONE) from sysibm.sysdummy1; --    - timestamp(generate_unique()) from sysibm.sysdummy1;


-- 169017 - ZG - Neue Bank "UBS Switzerland"
select * from vista.tpvbankbasic where clearingnr='225';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME            ADDRESS1           ADDRESS2  ZIP     CITY    BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ------------------  -----------------  --------  ------  ------  --------  ----------  ----------  ----------  -------------------  
457943179  2447555    (null)   225         UBS Switzerland AG  Theaterstrasse 20  (null)    800100  Zrich  0         Country#CH  2018-01-01  9999-12-31  2018-01-25 12:53:22  
2447554    2447555    (null)   225         UBS Zrich          Seefeldstrasse 15  (null)    803200  Zrich  0         Country#CH  1900-01-01  2017-12-31  2018-01-25 12:53:22  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=2447555;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
4438910      2447554        2447555        1900-01-01        9999-12-31      TPVBANKBASIC      0                         TFIRMA              686993870401513  1997-08-22 11:07:59  2009-03-05 00:04:30  
*/
-->  686993870401513

-- 168572 - ZH - EAdmin - Partner ohne Geb.-Dat.
select * from vista.jpvpartner where personid='7567057959246'; -- 3061934327 -- change-User: ZH1448; birthdate: 1995-05-18
select * from vista.tpvpartner where kpvpartid=3061934327;
select * from vista.tpvrole where kpvpartid=3061934327;
/*
TPVROLEID   KPVROLEID   KPVPARTID   CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
3061934328  3061934329  3061934327  Rolle#STA  (null)     (null)       (null)  1995-05-18  9999-12-31  2017-11-27 17:33:12  
3065296227  3065296228  3061934327  Rolle#VB   (null)     (null)       (null)  1995-05-18  9999-12-31  2017-11-28 07:53:33
*/
-- Doppelter Partner?
select * from vista.tpvpartner where personid='7567057959246'; -- 9007794
select * from vista.tpvrole where kpvpartid=9007794;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
9007805     9007810     9007794    Rolle#STA  (null)     (null)       (null)  1998-05-18  9999-12-31  2008-10-23 07:26:46  
41978386    41978388    9007794    Rolle#MA   (null)     (null)       (null)  1900-01-01  9999-12-31  2008-10-23 16:46:18  
88814534    88814539    9007794    Rolle#IPV  (null)     (null)       (null)  2000-12-29  9999-12-31  2009-05-15 20:36:28  
1730021165  1730021166  9007794    Rolle#VB   (null)     (null)       (null)  1998-05-18  9999-12-31  2015-06-04 22:38:40  
*/

select count(distinct kpvpartid) as cnt_nnss_cntry from vista.tpvpartner where cpartnertype like '%#NP' and personid is not null and ccitizenship is null; -- SG: 19'972 
  
select count(distinct a.kpvadrsid) as cnt_adrs from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where ab.ispobox='Y'; -- SG: 22773
select count(distinct a.kpvadrsid) as cnt_adrs from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where ab.ispobox='Y' and length(a.streetnr) > 8; -- SG: 22773

select a.kpvadrsid, a.tpvadrsid, a.caddresstype, ab.street, a.streetnr, ab.zip, ab.city, ab.ccountry, ab.ispobox from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where ab.ispobox='Y' and length(a.streetnr) > 8;


-- IK-Verkettung: Partner gelscht?
select * from vista.tpvpartner p where p.personid is not null and exists (
    select 1 from vista.tikowner o where o.kpvroleid in (select r.kpvroleid, r.kpvpartid from vista.kpvrole r where r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
);


-- Migration BE: RWL: Rentenabtretung zulssig
select * from vista.tpvpartner where compfundcede = 'N';
select kpvpartid, tpvpartid, name, additionalname, compfundnr, compfundbranchnr, compfundcede, ccompfundtype, validfrom, validto from vista.tpvpartner where clegaltype='NNPersonTy#AK' and compfundcede = 'N' and validto='9999-12-31' and ccompfundtype in ('CompoundFu#F', 'CompoundFu#K');


-- nderung Partnertyp
select kpvpartid, name from vista.tpvpartner where clegaltype = 'NNPersonTy#NNP' and clegalform is null;


-- Banks and old Periods
select * from vista.tpvbankbasic b where b.validTo < current date
and not exists (
    select 1 from vista.tpvbankbasic b2 where b2.kpvbankid = b.kpvbankid and validTo > current date
);

-- Banks with different Clearing-Nr. in periods
select * from vista.tpvbankbasic b where b.ccountry='Country#CH'
and exists (
    select 1 from vista.tpvbankbasic b2 where b2.kpvbankid = b.kpvbankid and b2.tpvbankid <> b.tpvbankid and b2.clearingnr <> b.clearingnr
) order by kpvbankid;


-- 169338 - OW - Doppeltes Keymapping bei Triba Partner Bank AG entfernen
select * from vista.tpvbankbasic where clearingnr='6690'; -- 1318934
select * from vista.tbikeymapping2000 where vista_kpv_key=1318934; -- 2023333
delete from vista.tbikeymapping2000 where tbikeymapid=2023333;


-- 169782 - FR - Neue Bank "Raiffeisen Schweiz " erfassen
select * from vista.tpvbankbasic where clearingnr='80808'; -- 709847805
select * from vista.tbikeymapping2000 where vista_kpv_key=709847805;

--
select * from vista.tpvpartner where personid is not null; -- 7567827297745
select kpvpartid, personid from vista.tpvpartner where personid='7561078914345';
select kpvpartid, personid, count(*) as cnt from vista.tpvpartner where personid='7561078914345' group by kpvpartid, personid;
select distinct kpvpartid, personid from vista.tpvpartner where personid='7561078914345';

-- 170006 - LI - Notifikationskonzept
select * from vista.tpvlog;
select * from vista.tpvnotification where ctargetappl='BusinessAp#RE' and cstate='NotiState#PROCESSED' order by lastupdated desc;

-- 166233 / 163999 - ZG - 2. Adresse lschen
select * from vista.tbikeymapping2000 where edv2000_ZID_KEY = 47943193402860;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
4472896      2521448        2521450        1938-05-15        2013-04-11      TPVADDRESS        0                         TADRESSIERUNG       47943193402860   2017-06-29 16:36:15  2017-06-29 16:36:45  
415227203    415227177      415227178      2013-04-12        9999-12-31      TPVADDRESS        0                         TADRESSIERUNG       47943193402860   2017-09-28 09:31:27  2017-09-28 09:31:57  
*/
select * from vista.tpvaddress where kpvadrsid in (2521450, 415227178) order by kpvadrsid;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
2521448    1633791    952287               687090     2521450    AddressTyp#WS  (null)     (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        1938-05-15  2013-04-11  (null)         2017-06-29 16:35:07  
415227177  1633791    952287               504708     415227178  AddressTyp#WS  (null)     (null)     AppendixPo#V  7         7              (null)  N       AddressStr#CH  (null)        2013-04-12  9999-12-31  (null)         2017-09-28 09:29:56  
*/
select * from vista.jpvaddress_archive_cc0493 where kpvadrsid in (2521450, 415227178) order by kpvadrsid;
select kpvpartid, tpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid=1633791;
select billnbr, adr1, kpvcorraddress, edv2000partnerid, validfrom, validto from vista.tikemployerarchive where kpvcorraddress in (2521450, 415227178);
/*
BILLNBR  ADR1            KPVCORRADDRESS  EDV2000PARTNERID  VALIDFROM   VALIDTO     
-------  --------------  --------------  ----------------  ----------  ----------  
560268   Anna Hrlimann  2521450         519083193302860   1997-01-01  2000-05-31  
036780   Anna Hrlimann  2521450         519083193302860   2013-09-24  9999-12-31  
*/
update vista.tikemployerarchive set kpvcorraddress=415227178, lastupdated=current timestamp where kpvcorraddress=2521450;
delete from vista.tpvaddress where kpvadrsid=2521450;


-- 169807 - OW - PV-Eintrag muss gelscht werden
select kpvpartid, tpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where name='Durrer' and firstname='Thomas' and birthdate='1965-02-07'; -- 3876401
/*
KPVPARTID  TPVPARTID  NAME    FIRSTNAME  PERSONID       VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ------  ---------  -------------  ----------  ----------  -------------------  
3876401    3876400    Durrer  Thomas     (null)         1965-02-07  9999-12-31  2018-02-02 13:06:48  
15318908   15318907   Durrer  Thomas     7565533227964  1965-02-07  9999-12-31  2018-01-31 15:47:17  
*/
select * from vista.tpvrole where kpvpartid=3876401; -- STA: 3876403
select * from vista.tpvrolerel where kpvroleid_source=3876403 or kpvroleid_target=3876403;
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT      MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  ---------------------  ------------------  -----------  -------------------  
14358793   14358792          3876403           (null)     14358794   3876420         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2011-08-23  2018-01-30  Correspond#REK      Guten Tag Herr Durrer                      (null)       2018-02-02 13:15:34  
*/
select * from vista.tpvaddress where kpvpartid=3876401;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
3876419    3876401    (null)               779377     3876420    AddressTyp#WS                        AppendixPo#V  10        10             (null)  N       AddressStr#CH  (null)        2001-01-01  9999-12-31  (null)         2010-03-17 17:05:11  
*/
-- 1) Delete Address 3876420
-- 2) Delete role-relation TPVRRELID
-- 3) Delete STA-Role 3876403
-- 4) Delete Partner 3876401

select * from vista.tiscmcode where shortcode='PVCONST_55';


-- 171015 - TG - 2 Flle nicht repliziert
select * from vista.tpvpartner where kpvpartid=42894187;
select * from vista.tpvaddress where kpvpartid=42894187; -- 718906800

select * from vista.tpvpartner where kpvpartid=43044859;
select * from vista.tpvaddress where kpvpartid=43044859; -- 718924584

-- 170747 - SO - Adresse nicht im Host
select * from vista.tpvpartner where name='Concetto' and firstname='Sentina'; -- empty
select * from vista.tpvpartner where name='Sentina' and firstname='Concetto'; -- 3235516 (NNSS = 7560484083249)
select * from vista.tpvaddress where kpvpartid=3235516; -- 7533829 --> mutiert von ZA auf AA (2018-02-15 07:32:48)
select * from vista.tbiprocessed_uow where vista_kpv_key=7533829; -- P am 2018-02-15 07:33:43
select * from vista.tbikeymapping2000 where vista_kpv_key=7533829;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
12795927     7533828        7533829        1996-01-01        9999-12-31      TPVADDRESS        0                         TZAHLVERBIND        957396071501420  1997-05-14 16:41:23  2009-03-05 03:55:53  
*/
--> EDV2000_TABLE_NAME = TZAHLVERBIND (Statt TADRESSIERUNG)
--> Hintergrund: war ursprnglich an eine migrierte Zahlungsanweisung geknpft
--> Workaround gemss Doku


-- 170912 - OW - AK 066.000 kann nicht mutiert werden
select kpvpartid, tpvpartid, name, compfundnr, compfundbranchnr, compfundcede, ccompfundfaktype, validfrom, validto, lastupdated from vista.tpvpartner where name='consimo - Ausgleichskasse 66 SBV';
/*
KPVPARTID  TPVPARTID  NAME                              COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDFAKTYPE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  --------------------------------  ----------  ----------------  ------------  ----------------  ----------  ----------  -------------------  
1258980    1258979    consimo - Ausgleichskasse 66 SBV  66          150               Y             FAKCompoun#EIG    1900-01-01  9999-12-31  2018-02-07 15:23:11  
1303433    218755962  consimo - Ausgleichskasse 66 SBV  66          4                 N             FAKCompoun#NAN    2018-01-01  9999-12-31  2018-02-07 15:25:44  
*/
select kpvpartid, tpvpartid, name, compfundnr, compfundbranchnr, compfundcede, ccompfundfaktype, validfrom, validto, lastupdated from vista.tpvpartner where compfundnr=66 and compfundbranchnr=0;
/*
KPVPARTID  TPVPARTID  NAME                  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDFAKTYPE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  --------------------  ----------  ----------------  ------------  ----------------  ----------  ----------  -------------------  
1303433    1303468    AK Baumeisterverband  66          0                 Y             (null)            2000-01-01  2017-12-31  2018-02-05 15:01:42  
*/
select * from vista.tpvemployee;

select distinct personid, count(*) as cnt from vista.tpvpartner group by kpvpartid, personid having personid is not null and count(*) > 1;
select * from vista.tpvpartner where personid='7560007800988';

select distinct p1.personid, (select count(distinct p3.kpvpartid) from vista.tpvpartner p3 where p3.personid = p1.personid) as cnt from vista.tpvpartner p1
left join vista.tpvpartner p2 on (p2.personid = p1.personid and p2.kpvpartid <> p1.kpvpartid)
where p1.personid is not null
order by 2 desc;


-- 170774 - eduSG - 8-stellige Abr.-Nr. und UID wird bei Suche mit Part-ID in Indizierung nicht bergeben
/*
15.02.18 15:26:18.85: searchPartners: searchValues={{PID=487414046203716},{PHONETIC=0}}
15.02.18 15:26:19.23: searchPartnersVistaReturnValues: return={IDs, 487414046203716, MainName, Marfurt, SubName, Stephan, SocialSecurityNumber, 63060234118, NewSocialSecurityNumber, 7560859997829, BillingNumber, NULL, Appelation, Herr, Title, Dr., BirthDate, 19600503, DocumentAuthorization, 0, PrivateStreet, Rosenbchelstrasse, PrivateStreeNo, 15, PrivateZipCode, 9014, PrivateCity, St. Gallen, PrivateCountry, CH, CompanyStreet, Rosenbchelstrasse, CompanyStreetNo, 15, CompanyZipCode, 9014, CompanyCity, St. Gallen, CompanyCountry, CH, PrivateSex, M, PrivateLanguage, D, CompanyLanguage, NULL, UID, NULL, } (searchValues={{PID=487414046203716},{PHONETIC=0}})
15.02.18 15:26:19.25: searchPartners: return={{{487414046203716}},{Appellation=Herr},{BillingNumber=},{BirthDate=03.05.1960 00:00:00},{CompanyCity=St. Gallen},{CompanyCountry=CH},{CompanyStreet=Rosenbchelstrasse},{CompanyStreetNo=15},{CompanyZipCode=9014},{DocumentAuthorization=0},{MainName=Marfurt},{NewSocialSecurityNumber=7560859997829},{PrivateCity=St. Gallen},{PrivateCountry=CH},{PrivateStreet=Rosenbchelstrasse},{PrivateStreetNo=15},{PrivateZipCode=9014},{SocialSecurityNumber=63060234118},{SubName=Stephan},{Title=Dr.},{Sex=M},{Language=D},{CompanyLanguage=},{Uid=},} (searchValues={{PID=487414046203716},{PHONETIC=0}})
*/
select * from vista.tpvelarpid where elarpid='487414046203716';
/*
TPVELHYID  KPVPARTID  ELARPID          DEFAULT  LASTUPDATED          
---------  ---------  ---------------  -------  -------------------  
1300484    1300480    487414046203716  1        2008-06-19 09:24:15  
*/
select * from vista.tpvpartner where kpvpartid=1300480; -- PartnerTyp#NP: Stephan Marfurt
select * from vista.tbikeymapping2000 where vista_kpv_key=1300480; -- 487414046203716
select tikearcid, billnbr, adr1, uid, edv2000partnerid, validfrom, validto, bwregisteroid, kpvpartner, lastupdated from vista.tikemployerarchive where kpvpartner=1300480 or edv2000partnerid=487414046203716;
/*
TIKEARCID   BILLNBR   ADR1             UID           EDV2000PARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  LASTUPDATED          
----------  --------  ---------------  ------------  ----------------  ----------  ----------  ------------------------------------  ----------  -------------------  
596739970   F81719    Stephan Marfurt  CHE109401386  487414046203716   2002-01-01  9999-12-31  d8562572-9f53-4e8a-9eda-515c48118f74  1300480     2018-02-06 16:46:19  
1418028721  20000029  (null)           CHE109401386  (null)            2017-01-01  9999-12-31  56695426-491d-44dc-b5e5-9c951115388b  1300480     2018-02-06 16:46:19  
1418028734  20000030  (null)           CHE109401386  (null)            2017-01-01  9999-12-31  81dc6179-66f7-46a9-867c-d031ae31de1a  1300480     2018-02-06 16:46:19  
*/

select * from vista.aurupiregister;

-- 171428 - TG - IBAN-Zahlempfnger nicht bernommen
-- 756.3335.1013.76
select * from vista.tpvpartner where personid='7563335101376'; -- 4544634 -- Christian Devoivre (source)
select * from vista.tpvrole where kpvpartid=4544634;
select * from vista.tpvrolerel where kpvroleid_source in (select kpvroleid from vista.tpvrole 
where (kpvpartid=4544634) or kpvroleid_target in (select kpvroleid from vista.tpvrole where kpvpartid=4544634)) 
and crelationtype='RoleRelati#ZE';
select * from vista.tpvpartner where personid='7563381210589'; -- 4400099 -- Jrme (target)
select * from vista.tpvrole where kpvpartid=4400099;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
4400104    4400106    4400099    Rolle#STA  (null)     (null)       (null)  1998-05-19  9999-12-31  2009-08-27 04:34:53  
8934387    8934389    4400099    Rolle#MA   (null)     (null)       (null)  1900-01-01  9999-12-31  2009-08-27 06:21:38  
247744906  247744905  4400099    Rolle#IV   (null)     (null)       (null)  1998-05-19  9999-12-31  2013-11-11 19:59:48  
*/
select * from vista.tpvrolerel where kpvroleid_source in (select kpvroleid from vista.tpvrole 
where (kpvpartid=4544634) and kpvroleid_target in (select kpvroleid from vista.tpvrole where kpvpartid=4544634)) and crelationtype='RoleRelati#ZE';
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT  MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  -----------------  ------------------  -----------  -------------------  
37407061   37407037          4544652           37407060   37407062   (null)          (null)          4544634               RoleRelati#ZE  (null)           PaymentAdd#RE      (null)         (null)               2011-01-01  2017-12-31  (null)              (null)             (null)              (null)       2018-02-26 11:03:17  
37407066   37407037          4544652           37407065   37407067   (null)          (null)          (null)                RoleRelati#ZE  (null)           PaymentAdd#RE      (null)         (null)               2011-01-01  9999-12-31  (null)              (null)             (null)              (null)       2011-06-25 03:15:19  
153045170  37407037          4544652           7941935    153045171  (null)          (null)          4544634               RoleRelati#ZE  (null)           PaymentAdd#RE      (null)         (null)               2012-04-26  2017-12-31  (null)              (null)             (null)              (null)       2018-02-26 11:03:06  
*/

-- 171431 - ZH - VB-Schutzstufe
select * from vista.tpvpartner where personid='7565358789395';

select distinct civilstatuscd from vista.aurupiregister;
select * from vista.aurupiregister where civilstatuschange like '01%';


-- 171422 - LI - Pensionskasse nicht terminierbar
select * from vista.tpvpartner where name='Pensionsversicherung'; -- 1856227
select * from vista.tpvaddress where kpvpartid=1856227;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
54105976   1856227    (null)               917221     54105977   AddressTyp#ZA  (null)     (null)     AppendixPo#V  684       684            (null)  N       AddressStr#CH  (null)        1900-01-01  2014-06-30  (null)         2018-02-26 09:57:53  
1890760    1856227    22269345             19912      1890762    AddressTyp#GS  (null)     (null)     AppendixPo#V  11        11             (null)  N       AddressStr#CH  (null)        1900-01-01  9999-12-31  (null)         2018-02-26 09:58:47  
*/
select * from vista.tpvrolerel where kpvadrsid_corr in (54105977); -- terminierte Adresse -- empty
select * from vista.tpvrolerel where kpvadrsid_corr in (1890762) order by validto desc; -- 487
select * from vista.tpvrolerel where kpvadrsid_corr in (1890762) and validto > current date ;

select * from vista.nbdpostfilezip;
select * from vista.aurupiregister;
select * from syscat.tabauth where tabname like '_BDPOSTFILEZIP';
/*
GRANTOR   GRANTORTYPE  GRANTEE                    GRANTEETYPE  TABSCHEMA  TABNAME         CONTROLAUTH  ALTERAUTH  DELETEAUTH  INDEXAUTH  INSERTAUTH  REFAUTH  SELECTAUTH  UPDATEAUTH  
--------  -----------  -------------------------  -----------  ---------  --------------  -----------  ---------  ----------  ---------  ----------  -------  ----------  ----------  
DB2ADM    U            LG-SIT17-DB-LZ-DB2-VIS-RO  G            VISTA      TBDPOSTFILEZIP  N            N          N           N          N           N        Y           N           
DB2ADM    U            LG-SIT17-DB-LZ-DB2-VIS-RW  G            VISTA      TBDPOSTFILEZIP  N            Y          Y           Y          Y           Y        Y           Y           
DB2ADM    U            LG-SIT17-DB-LZ-DB2-IPV-RO  G            VISTA      TBDPOSTFILEZIP  N            N          N           N          N           N        Y           N           
DB2ADM    U            LG-SIT17-DB-LZ-DB2-IPV-RW  G            VISTA      TBDPOSTFILEZIP  N            N          Y           N          Y           N        Y           Y           
DB2ADM    U            LG-SIT17-DB-LZ-DB2-DKA-RW  G            VISTA      TBDPOSTFILEZIP  N            Y          Y           Y          Y           Y        Y           Y           
DB2ADM    U            DUSIT17                    U            VISTA      TBDPOSTFILEZIP  N            N          Y           N          Y           N        Y           Y           
DB2ADM    U            IUSIT17                    U            VISTA      TBDPOSTFILEZIP  N            N          Y           N          Y           N        Y           Y           
DB2ADM    U            IKSIT17                    U            VISTA      TBDPOSTFILEZIP  N            N          Y           N          Y           N        Y           Y           
DB2ADM    U            DKSIT17                    U            VISTA      TBDPOSTFILEZIP  N            N          Y           N          Y           N        Y           Y           
*/


-------- SQL-Aufgaben fr Newbies --------------------------------------------------

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate as geburi, p.validfrom as p_validfrom, p.validto as p_valid_to,
a.kpvadrsid, a.tpvadrsid, a.caddresstype, ab.street, a.streetnr, ab.zip, ab.city, ab.ccountry, a.validfrom as a_validfrom, a.validto as a_validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where p.name = 'Fournier';

SELECT 
p.KPVPARTID,
p.TPVPARTID,
p.NAME,
p.FIRSTNAME,
p.BIRTHDATE,
p.VALIDFROM,
p.VALIDTO, 
a.KPVADRSID,
a.TPVADRSID,
a.CADDRESSTYPE,
b.STREET,
a.STREETNR,
b.ZIP,
b.CITY,
b.CCOUNTRY,
a.VALIDFROM,
a.VALIDTO
FROM VISTA.TPVPARTNER p
LEFT JOIN VISTA.TPVADDRESS a
ON (p.KPVPARTID = a.KPVPARTID)
LEFT JOIN VISTA.TPVADDRESSBASIC b
ON (a.KPVADBAID = b.KPVADBAID)
WHERE
p.NAME LIKE 'Fournier'
ORDER BY BIRTHDATE ASC;

----------------------------------------------------------

-- NullPointer auf AG-Rolle, alte Abr.-Nr.
select * from vista.tikemployerarchive where billnbr='10010025065';
/*
TIKEARCID  BILLNBR      BILLNBROLD    CBRANCHCODE  ADR1                                     ADR2  ADR3             ADR4               KPVCORRADDRESS  UID     CREGISTERCODE  CLEGALFORM  CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -----------  ------------  -----------  ---------------------------------------  ----  ---------------  -----------------  --------------  ------  -------------  ----------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  ------------  -------------------  
69944837   10010025065  738500009160  BRANCHE#60   Finanzverwaltung des Kantons St. Gallen        Davidstrasse 35  900000 St. Gallen  (null)          (null)  (null)         (null)      EADMINCODE#N  176493                64696             121628                (null)                    1948-01-01  1980-12-31  (null)         10612613    (null)          14849949            (null)        51395385  MEMBERTYP#AK  2018-03-02 07:36:34  
*/
select * from vista.tikemployerarchive where kpvpartner=10612613;
/*
TIKEARCID  BILLNBR      BILLNBROLD    CBRANCHCODE  ADR1                                     ADR2                    ADR3             ADR4               KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -----------  ------------  -----------  ---------------------------------------  ----------------------  ---------------  -----------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
69944837   10010025065  738500009160  BRANCHE#60   Finanzverwaltung des Kantons St. Gallen                          Davidstrasse 35  900000 St. Gallen  (null)          (null)        (null)           (null)        EADMINCODE#N  176493                64696             121628                (null)                    1948-01-01  1980-12-31  (null)                                10612613    (null)          14849949            (null)         51395385  MEMBERTYP#AK  2018-03-02 07:36:34  
597074204  350900       (null)        BRANCHE#84   Personalamt                              des Kantons St. Gallen  Davidstrasse 35  9000 St. Gallen    14849949        CHE114965275  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#N  73346                 64696             28986                 64696                     1948-01-01  9999-12-31  cbe05462-5f66-4d39-be12-d9dac0d5728d  10612613    10612613        14849949            SONDERFALL#03  956577    MEMBERTYP#AK  2018-03-01 18:10:47  
*/
select * from vista.tpvrole order by lastupdated desc; -- MA: kpvroleid=1437298614, kpvpartid=10612613
update vista.tpvrole set croletype='Rolle#AG', lastupdated=current timestamp where kpvroleid=1437298614;

select * from vista.tpvrole where kpvpartid=10612613;

-- AIT301 (Hase Fuchs)
select * from vista.tpvrole order by lastupdated desc;
select * from vista.tikemployerarchive order by lastupdated desc;
update vista.tikemployerarchive set adr2 = null where billnbr='10010025065';
update vista.tikemployerarchive set kpvpartner=168089088, lastupdated=current timestamp where tikearcid in (1050006, 1050080);
select * from vista.tpvpartner where name like '20 Minuten%'; -- 168089088
select * from vista.tbikeymapping2000 where vista_kpv_key=168089088;


-- 172443 - SG - NullPointer bei PV-WP-01
select * from vista.tpvpartner where personid='7569301653818'; -- 1100214212 -- nichts aufflliges
select * from vista.tpvelarpid where elarpid='V1100214212';
/*
TPVELHYID   KPVPARTID   ELARPID      DEFAULT  LASTUPDATED          
----------  ----------  -----------  -------  -------------------  
1100214215  1100214212  V1100214212  1        2016-11-30 14:31:02  
*/
select * from vista.tpvrole where kpvpartid=1100214212;
/*
TPVROLEID   KPVROLEID   KPVPARTID   CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
1100214213  1100214214  1100214212  Rolle#STA  (null)     (null)       (null)  1985-09-10  9999-12-31  2016-11-30 14:31:02  
1226864609  1226864610  1100214212  Rolle#VB   (null)     (null)       (null)  1985-09-10  9999-12-31  2017-04-10 08:21:18  
1442288395  1442288394  1100214212  Rolle#AB   (null)     (null)       (null)  2016-11-01  9999-12-31  2018-03-02 15:26:08  
*/

-- AIT301 - 20 Minuten AG
select * from vista.tpvpartner where kpvpartid=168089088;
select * from vista.tpvrole where kpvpartid=168089088;
/*
TPVROLEID         KPVROLEID         KPVPARTID  CROLETYPE  BILLINGNR     CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------------  ----------------  ---------  ---------  ------------  -----------  ------  ----------  ----------  -------------------  
168089089         168089090         168089088  Rolle#STA  (null)        (null)       (null)  2007-08-17  9999-12-31  2008-05-23 10:57:29  
9000003000003450  9000003000003450  168089088  Rolle#MG   10034809      (null)       (null)  2006-01-01  9999-12-31  2007-08-17 13:03:00  
9000003000003451  9000003000003451  168089088  Rolle#AG   10034809.001  (null)       (null)  2006-01-01  9999-12-31  2007-08-17 13:06:00  
9500000004641210  9500000004641211  168089088  Rolle#VET  (null)        (null)       (null)  2013-03-05  9999-12-31  2013-03-05 09:45:10  
*/
select * from vista.tpvelarpid where kpvpartid=168089088;
/*
TPVELHYID  KPVPARTID  ELARPID     DEFAULT  LASTUPDATED          
---------  ---------  ----------  -------  -------------------  
168089091  168089088  V168089088  1        2007-08-17 10:35:04  
*/
update vista.tpvrole set croletype='Rolle#VB', lastupdated = current timestamp where kpvroleid=9000003000003450;
update vista.tpvrole set croletype='Rolle#AB', lastupdated = current timestamp where kpvroleid=9000003000003451;

select p.*, p.name, p.personid, r1.croletype, r2.croletype from vista.tpvpartner p
left join vista.tpvrole r1 on (r1.kpvpartid = p.kpvpartid and r1.croletype='Rolle#AB')
left join vista.tpvrole r2 on (r2.kpvpartid = p.kpvpartid and r2.croletype='Rolle#VB')
where p.validto='9999-12-31' and r1.croletype is not null and r2.croletype is not null;


-- EG
select * from vista.tpvpartner where clegaltype='NNPersonTy#EG'; -- clegalform like '%EG'; -- = 'NNPersonTy#EG';

-- Kosovo
-- PV
select count(distinct kpvpartid) as cnt_xz_nationality from vista.tpvpartner where ccitizenship='Country#XZ'; -- SG: 8742
select count(distinct kpvpartid) as cnt_xz_col from vista.tpvpartner where ccountryofliving='Country#XZ'; -- SG: 38
select count(distinct kpvpaddid) as cnt_xz_pa from vista.tpvpaymentaddr where ccountry='Country#XZ'; -- SG: 0
select count(distinct kpvadbaid) as cnt_xz_ab from vista.tpvaddressbasic where ccountry='Country#XZ'; -- SG: 41
select count(distinct kpvbankid) as cnt_xz_bank from vista.tpvbankbasic where ccountry='Country#XZ'; -- SG: 0
-- RE
select count(distinct kpvpartid) as cnt_xz_re_nationality from vista.treperson where ccitizenship='Country#XZ'; -- SG: 1179
select count(distinct kpvpartid) as cnt_xz_re_col from vista.treperson where ccountryofliving='Country#XZ'; -- SG: 453

-- Historisierung
select tpvpartid, kpvpartid, name, firstname, csex, ccitizenship, ccountryofliving, ccivilstatus, civilstatussince, validfrom, validto from vista.tpvpartner order by kpvpartid;

-- 172747 / 169705 - ZG - Bank fehlt
select * from vista.tpvbankbasic where clearingnr='81491';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME            ADDRESS1           ADDRESS2  ZIP     CITY        BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ------------------  -----------------  --------  ------  ----------  --------  ----------  ----------  ----------  -------------------  
471011007  471011008  (null)   81491       Raiffeisen Schweiz  Raiffeisenplatz 4  (null)    900000  St. Gallen  0         Country#CH  1900-01-01  9999-12-31  2018-03-12 14:54:52  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=471011008; -- empty
-- 169705: Bezieht sich auf Raiffeisen Schweiz mit der Clearing-Nr. 80808 erfassen
select * from vista.tpvbankbasic where clearingnr='80808';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME            ADDRESS1         ADDRESS2  ZIP     CITY        BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ------------------  ---------------  --------  ------  ----------  --------  ----------  ----------  ----------  -------------------  
459961341  459961342  (null)   80808       Raiffeisen Schweiz  Raiffeisenplatz  (null)    900000  St. Gallen  0         Country#CH  1900-01-01  9999-12-31  2018-02-01 11:43:53  
*/

-- Anfrage AL: Copy-Paste Abr.-Nr. auf Mitglied-Info GUI?
select * from vista.tikemployerarchive; -- Nicolas Fournier
update vista.tikemployerarchive set kpvpartner=30005, lastupdated=current timestamp where tikearcid=1050290; -- D78250

-- Anfrage AL: Terminierter Adressstamm
select * from vista.tpvaddressbasic where street='Suppenstrasse';
/*
TPVADBAID  KPVADBAID  STREET         STREETSX  UPPERSTREET    ZIP     CITY    CITYSX  UPPERCITY  CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------------  --------  -------------  ------  ------  ------  ---------  ---------  ----------  -------  ----------  ----------  -------------------  
167971346  167971347  Suppenstrasse  S152      SUPPENSTRASSE  606000  Sarnen  S655    SARNEN     Canton#OW  Country#CH  N        1900-01-01  9999-12-31  2007-04-10 09:16:35  
*/
update vista.tpvaddressbasic set validto='2015-12-31', lastupdated=current timestamp where kpvadbaid=167971347; -- Suppenstrasse

-- UPI changed entries

select * from vista.aurupiregister where statuscd='1' and old_ahv_or_nnss <> new_nnss;
select * from vista.aurupiregister where new_nnss='7562898095405';
select * from vista.aurupiregister where new_nnss='7562898095405' and turupiregisterid in (4611686018435823735, 4611686018435840895);

-- 173438 - ZG - Raiffeisenbank Hitzkirchertal
select * from vista.tpvbankbasic where clearingnr='81169';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME        ADDRESS1  ADDRESS2  ZIP     CITY       BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  --------------  --------  --------  ------  ---------  --------  ----------  ----------  ----------  -------------------  
5277212    5277213    (null)   81169       Raiffeisenbank  (null)    (null)    628500  Hitzkirch  0         Country#CH  2001-06-20  9999-12-31  2009-08-27 04:47:21  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=5277213;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
12361830     5277212        5277213        2001-06-20        9999-12-31      TPVBANKBASIC      0                         TFIRMA              211313171203093  2001-06-20 08:48:32  2009-08-27 08:40:58  
*/

select * from vista.aurupiregister;

-- PV-WP-04 - R_TITLELINE - prodSG:
select * from vista.tpvpartner where kpvpartid=179161993; -- Prof. Dr.	Smoke
select * from vista.tpvrole where kpvpartid=179161993;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
347618379   347618380   179161993  Rolle#VB   (null)     (null)       (null)  1950-01-01  9999-12-31  2011-11-19 13:57:31  
179161994   179161995   179161993  Rolle#STA  (null)     (null)       (null)  2010-09-24  9999-12-31  2010-09-24 23:47:30  
179162085   179162086   179161993  Rolle#EL   (null)     (null)       (null)  1900-01-01  9999-12-31  2010-09-24 23:53:35  
179162241   179162242   179161993  Rolle#HE   (null)     (null)       (null)  2010-09-24  9999-12-31  2010-09-25 01:00:14  
179162327   179162328   179161993  Rolle#IK   (null)     (null)       (null)  2010-09-25  9999-12-31  2010-09-25 01:08:09  
1161394932  1161394933  179161993  Rolle#RE   (null)     (null)       (null)  2017-02-24  9999-12-31  2017-02-24 16:22:35  
*/
select rr.kpvrrelid, rr.kpvroleid_source, rr.kpvroleid_target, p.name, 
rr.kpvadrsid_corr, rr.crelationtype, rr.validfrom, rr.validto, rr.ccorraddresseetype, rr.manuallettersalut, rr.lastupdated
from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_target)
left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid)
where (rr.kpvroleid_source in (select r2.kpvroleid from vista.tpvrole r2 where r2.kpvpartid=179161993) or rr.kpvroleid_target in (179161995)) 
and rr.crelationtype='RoleRelati#KE' and rr.validto='9999-12-31';


-- 173965 - OW - Umlaute falsch in EDV2000
select * from vista.tbikeymapping2000 where edv2000_zid_key=838623974401426; -- 1047476
select tpvpartid, kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where kpvpartid=1047476;
/*
TPVPARTID  KPVPARTID  NAME       FIRSTNAME  VALIDFROM   VALIDTO     
---------  ---------  ---------  ---------  ----------  ----------  
1047474    1047476    Schrmann  Markus     1976-08-02  2008-04-24  
224552013  1047476    Schrmann  Markus     2018-01-31  9999-12-31  
3970155    1047476    Schrmann  Markus     2008-04-25  2018-01-30
*/
select tpvpartid, kpvpartid, name, uppername, firstname, ibmsnap_commitseq, ibmsnap_logmarker from vista.tgtpvpartner where kpvpartid=1047476;
-- Neue Flle?
select tpvpartid, kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where name like '%%' and date(lastupdated)='2018-04-03';
select tpvpartid, kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where name like '%%' and date(lastupdated)='2018-04-03';
select tpvpartid, kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where name like '%%' and date(lastupdated)='2018-04-03';



select count(*) from vista.tpvpartnerreplication where date(lastupdated) in  ('2018-03-29', '2018-03-28');
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and date(lastupdated) in  ('2018-03-29', '2018-03-28');

-- Revisionsstellen?
select * from vista.tpvpartner where name like 'Revision%';

-- UPI-Register: Status 2/3
select * from vista.aurupiregister where statuscd=3;
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
501535527         7564987809962    0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-03-07 09:28:14  
501535713         7564987867153    0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-03-07 09:28:14  
*/
select * from vista.aurupiregister where statuscd=2;
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
496264501            7563245391447    7564751087978  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-03-07 09:28:14  
496264533            7563245403676    7563468865312  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-03-07 09:28:14  
*/

select * from vista.tpvpartner where birthdateprec > 0;


select * from vista.tpvrolerel;

select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and cstatus='RepState#NEW'; -- SG: 1
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and cstatus='RepState#ERROR'; -- SG: 0
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and cstatus='RepState#PROCESSED' and date(lastupdated) >= '2018-04-06' order by lastupdated desc; -- SG: 0
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and cstatus='RepState#NEW'; -- ZH: 31

select * from vista.aaireplication;

select * from vista.tpvpaymentaddr;

-- 171354 ZH 
select * from vista.tpvpartner; -- where personid='7568928080755';
select * from vista.tpvaddress;

select distinct p.kpvpartid, p.firstname, p.name, p.personid from vista.tpvpartner p where p.cpartnertype='PartnerTyp#NP' and p.validto='9999-12-31'
and exists (
    select 1 from vista.tpvaddress a1 where a1.kpvpartid=p.kpvpartid and a1.caddresstype='AddressTyp#GS'
) and not exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid=p.kpvpartid and a2.caddresstype='AddressTyp#WS'
);
--
select count(distinct p.kpvpartid) from vista.tpvpartner p where p.cpartnertype='PartnerTyp#NP' and p.validto='9999-12-31'
and exists (
    select 1 from vista.tpvaddress a1 where a1.kpvpartid=p.kpvpartid and a1.caddresstype='AddressTyp#GS'
) and not exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid=p.kpvpartid and a2.caddresstype='AddressTyp#WS'
); -- SG: 947


-- 174991 - ZH - 756.2774.0930.13 fehlt in EDV2000
select * from vista.tpvpartner where personid='7562774093013'; -- 20396998
select * from vista.tbiprocessed_uow where vista_kpv_key=20396998; -- Alles auf P seit 2018-01-19 08:57:49
select * from vista.tbikeymapping2000 where vista_kpv_key=20396998; -- EDV2000_ZID_Key = 340540

select * from vista.tbikeymapping2000 where edv2000_zid_key=10079441; -- 201450
select * from vista.tpvaddressbasic where kpvadbaid=201450;
/*
TPVADBAID   KPVADBAID  STREET       STREETSX  UPPERSTREET  ZIP     CITY    CITYSX  UPPERCITY  CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ---------  -----------  --------  -----------  ------  ------  ------  ---------  ---------  ----------  -------  ----------  ----------  -------------------  
201447      201450     Rainstrasse  R523      RAINSTRASSE  870602  Meilen  M450    MEILEN     Canton#ZH  Country#CH  N        1900-01-01  2016-08-25  2016-08-26 17:43:45  
2378889697  201450     Rainstrasse  R523      RAINSTRASSE  870600  Meilen  M450    MEILEN     Canton#ZH  Country#CH  N        2016-08-26  9999-12-31  2016-08-26 17:43:45  
*/


-- 174789 - LI - Rentenfall nicht anlegbar
select kpvpartid, tpvpartid, name, personid, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid=1645200;
/*
KPVPARTID  TPVPARTID  NAME    PERSONID  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ------  --------  ----------  ----------  -------------------  
1645200    8213922    Rader   24657     1958-02-03  1982-10-21  2018-03-29 09:22:30  
1645200    259163465  Fliri   24657     1982-10-22  1989-04-27  2018-03-29 09:22:50  
1645200    259163471  Fliri   24657     1989-04-28  1989-07-20  2018-03-29 09:23:39  
1645200    259163480  Kindle  24657     1989-07-21  2000-06-04  2018-03-29 09:23:53  
1645200    259163485  Kindle  24657     2000-06-05  2002-07-25  2018-03-29 09:24:10  
1645200    259163535  Kindle  24657     2002-07-26  9999-12-31  2018-04-10 08:23:57  
*/
select * from vista.tpvrole where kpvpartid=1645200;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
1645224    1645225    1645200    Rolle#STA  (null)     (null)       (null)  1958-02-03  2010-09-20  2010-09-21 16:04:30  
2436808    2436809    1645200    Rolle#MA   (null)     (null)       (null)  1900-01-01  9999-12-31  2009-06-04 00:03:07  
37679475   37679476   1645200    Rolle#IK   (null)     (null)       (null)  1958-02-03  9999-12-31  2012-06-26 00:47:22  
*/
--> STA-Rolle wieder auf 9999-12-31 setzen.


-- 174984 - ZH - Quellensteuer nicht in EDV2000
select kpvpartid, name, personid, ctaxatsource, validfrom, validto, lastupdated from vista.tpvpartner where personid='7560843696479'; -- 697260869, ctaxatsource
/*
KPVPARTID  NAME    PERSONID       CTAXATSOURCE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ------  -------------  ------------  ----------  ----------  -------------------  
697260869  Morina  7560843696479  Decision#J    1989-01-29  2017-01-17  2018-04-10 14:38:42  
697260869  Morina  7560843696479  Decision#J    2017-01-18  2017-12-31  2018-04-09 11:24:23  
697260869  Morina  7560843696479  Decision#N    2018-01-01  2018-02-28  2018-04-13 08:50:40  
697260869  Morina  7560843696479  Decision#J    2018-03-01  9999-12-31  2018-04-13 08:50:40  
*/

-- RE.2018.48825 Story: Update RCPV05 / RCPV35 interface to meet new requirements RE
-- AIT201
select * from vista.tpvpartner where firstname='Adoptivkind' and name='Fournier'; -- 63705
update vista.tpvpartner set firstname='Pflegekind' where firstname='Adoptivkind' and name='Fournier';


-- 174385 - TG - IK / PV / Partner wurde durch IK Bearbeitung terminiert
select * from vista.tpvpartner where name='Kreick' and firstname='Ida'; -- 722376271
select tpvpartid, kpvpartid, name, firstname, personid, validfrom, validto, change_date, change_user, program, operation from vista.jpvpartner where kpvpartid=722376271;
/*
TPVPARTID  KPVPARTID  NAME    FIRSTNAME      PERSONID       VALIDFROM   VALIDTO     CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
---------  ---------  ------  -------------  -------------  ----------  ----------  -------------------  -----------  ---------------------------------------  ---------  
722376270  722376271  Kreick  Ida Elizabeth  7560000000057  2018-01-12  9999-12-31  2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376270  722376271  Kreick  Ida Elizabeth  7560000000057  2018-01-12  9999-12-31  2018-02-27 16:48:34  tgre         PV:PV-Dlg-201 Person                     U          
722376270  722376271  Kreick  Ida Elizabeth  7564474907416  2018-01-12  9999-12-31  2018-02-27 16:50:23  tgre         PV:PV-Dlg-201 Person                     U          
722376270  722376271  Kreick  Ida            7564474907416  2018-01-12  9999-12-31  2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  U          
722376270  722376271  Kreick  Ida            (null)         2018-01-12  9999-12-31  2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  U          
722376270  722376271  Kreick  Ida            (null)         2018-01-12  2018-03-08  2018-03-12 13:49:17  tgtmu        PV:PV-Dlg-701 Dialog Periode Person      U          
722376270  722376271  Kreick  Ida            (null)         2018-01-12  9999-12-31  2018-03-12 13:49:27  tgtmu        PV:PV-Dlg-701 Dialog Periode Person      U          
*/
select * from vista.tpvaddress where kpvpartid=722376271;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
723816784  722376271  27274807             343288865  723816785  AddressTyp#WS  (null)     (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-01-12  9999-12-31  (null)         2018-03-12 13:49:10  
*/
select * from vista.jpvaddress where kpvpartid=722376271;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                               OPERATION  
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  -------------------  -----------  ------------------------------------  ---------  
723816784  722376271  27274807             343288865  723816785  AddressTyp#WS  (null)     (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-02-27  9999-12-31  (null)         2018-02-27 16:50:11  2018-02-27 16:50:11  tgre         PV:PV-Dlg-301 Adresse                 I          
723816784  722376271  27274807             343288865  723816785  AddressTyp#WS  (null)     (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-02-27  9999-12-31  (null)         2018-02-27 16:50:11  2018-03-12 13:49:10  tgtmu        PV:PV-Dlg-702 Dialog Periode Adresse  U          
*/
select * from vista.tpvrole where kpvpartid=722376271;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
722376280  722376281  722376271  Rolle#STA  (null)     (null)       (null)  2018-01-12  9999-12-31  2018-03-12 13:49:17  
*/
select * from vista.jpvrole where kpvpartid=722376271;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
722376280  722376281  722376271  Rolle#STA  (null)     (null)       (null)  2018-01-12  9999-12-31  2018-02-23 09:02:15  2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376284  722376285  722376271  Rolle#IK   (null)     (null)       (null)  2018-02-23  9999-12-31  2018-02-23 09:02:15  2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376284  722376285  722376271  Rolle#IK   (null)     (null)       (null)  2018-02-23  9999-12-31  2018-02-23 09:02:15  2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  D          
722376280  722376281  722376271  Rolle#STA  (null)     (null)       (null)  2018-01-12  9999-12-31  2018-02-23 09:02:15  2018-03-12 13:49:17  tgtmu        PV:PV-Dlg-701 Dialog Periode Person      U          
*/
select * from vista.jikowner where kpvroleid=722376285;
/*
TIKOWNRID  KPVROLEID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
---------  ---------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
722376288  722376285  2018-02-23 09:02:15  2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376288  722376285  2018-02-23 09:02:15  2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  D          
*/
select * from vista.jikheader where tikownrid=722376288;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                  BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
---------  ---------  -------------  --------------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
722376289  722376288  7560000000057  KREICK,IDA ELIZABETH  2018       1           12        SEXCODEZAS#2  BSVLAND#207  (null)    T                2018-02-23 09:02:15  2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376289  722376288  7560000000057  KREICK,IDA ELIZABETH  2018       1           12        SEXCODEZAS#2  BSVLAND#207  (null)    T                2018-02-23 09:02:15  2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  D          
*/
select * from vista.jikinsurancerequest where customer=722376285; -- empty
select tikvaikreqid, kpvroleid, tikviooid, deliveryaddressik, csz, requestdate, transmissiondate, change_date, change_user, program, operation from vista.jikvaikrequest where kpvroleid=722376285;
/*
TIKVAIKREQID  KPVROLEID  TIKVIOOID  DELIVERYADDRESSIK  CSZ       REQUESTDATE  TRANSMISSIONDATE  CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
------------  ---------  ---------  -----------------  --------  -----------  ----------------  -------------------  -----------  ---------------------------------------  ---------  
722376291     722376285  722375486  722376290          SZMZR#19  2018-02-23   (null)            2018-02-23 09:02:15  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
722376291     722376285  722375486  722376290          SZMZR#19  2018-02-23   (null)            2018-02-23 20:34:46  TGIK0A01     IK:IKJB10101:722540981                   U          
722376291     722376285  722375486  722376290          SZMZR#19  2018-02-23   2018-02-23        2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  U          
722376291     722376285  722375486  727859974          SZMZR#19  2018-02-23   2018-02-23        2018-03-07 08:34:38  tglro        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  D          
*/


-- 175932 - ZH - Mutationen nicht in ELAR (Schutzstufe)
select * from vista.tpvpartner where personid='7566549352527'; -- 11746253 (2018-04-27 09:27:13)
select * from vista.tpvpartnerreplication where kpvpartid=11746253;
/*
TPVPARTREPID  KPVPARTID  VALIDFROM   CTARGETAPPL    CSTATUS             CREATIONRUN  CREATIONTIME         REPLICATIONRUN  REPLICATIONTIME  LASTUPDATED          
------------  ---------  ----------  -------------  ------------------  -----------  -------------------  --------------  ---------------  -------------------  
3311403702    11746253   2000-12-06  BusinessAp#EI  RepState#PROCESSED  3311403541   2018-04-27 09:30:30  (null)          (null)           2018-04-28 18:47:05  
3311403717    11746253   2000-12-06  BusinessAp#AI  RepState#PROCESSED  3311403541   2018-04-27 09:30:30  (null)          (null)           2018-04-27 09:31:09  
*/


-- TEMP / ISVIC - Frage AndrÃƒÆ’Ã‚Â©, 04.05.2018
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp='Y'; -- 16690
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp='Y' and validto > current date; -- 16689
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp='Y' and validto > current date and personid is not null; -- 180
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp='Y' and date(lastupdated) > '2018-01-01'; -- 0
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp is null; -- 95329
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp is null and date(lastupdated) > '2018-01-01'; -- 95328
select count(*) as cnt_tmp from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp is null and date(lastupdated) < '2018-01-01'; -- 1

--
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp='Y' and validto > current date; -- AIT: 999994080000022
update vista.tpvpartner set temp=null where kpvpartid=999994080000022;
select * from vista.tpvpartner where kpvpartid=999994080000022;


select * from syscat.tables where tabname like '%TPVPARTNER';
select * from syscat.tabauth where tabname like '%TPVPARTNER';

select * from vista.tpvpartner where birthdateprec=2;


-- 177199 - ZH - Adresse nicht in EDV2000
-- Fall 1:
-- 7563548536804
select * from vista.tpvpartner where personid='7563548536804'; -- 22308837 (Janine Tarolli)
select * from vista.tpvaddress where kpvpartid=22308837; -- 29529699 (WS)
/*
Janine Tarolli
8610 Uster
*/
select * from vista.tbiprocessed_uow where vista_kpv_key=29529699;
/*
TBIPROCUOWID  IBMSNAP_COMMITSEQ     IBMSNAP_INTENTSEQ     VISTA_TABLE_NAME  PROCESSING_STATE  VISTA_KPV_KEY  LASTUPDATED          
------------  --------------------  --------------------  ----------------  ----------------  -------------  -------------------  
3295210461    5AD5BF920000002E0000  00000000026159BA116C  TPVADDRESS        N                 29529699       2018-04-17 11:38:02  
3295210462    5AD5BF920000002E0000  00000000026159BA4D9D  TPVADDRESS        N                 29529699       2018-04-17 11:38:02  
3295210463    5AD5BF92000000300000  00000000026159BA8A8E  TPVADDRESS        N                 29529699       2018-04-17 11:38:02  
2971486576    59DCC3C4000000010000  000000000116F152DB5E  TPVADDRESS        N                 29529699       2017-10-10 14:58:11  
3188354322    5A743777000000030000  0000000001F65CE4AC53  TPVADDRESS        N                 29529699       2018-02-02 11:03:43  
3188354323    5A743777000000030000  0000000001F65CE4B217  TPVADDRESS        N                 29529699       2018-02-02 11:03:43  
3298942717    5AD88645000000080000  000000000264D09D3710  TPVADDRESS        N                 29529699       2018-04-19 14:07:05  
3298942718    5AD88645000000080000  000000000264D09D3E66  TPVADDRESS        N                 29529699       2018-04-19 14:07:05  
3298942720    5AD88647000000020000  000000000264D09DCD9A  TPVADDRESS        N                 29529699       2018-04-19 14:07:05  
3298942721    5AD88647000000020000  000000000264D09DD5F4  TPVADDRESS        N                 29529699       2018-04-19 14:07:05  
*/

-- Fall 2:
-- Rubbi Rothenfluh
select kpvpartid, tpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where lastname='Rothenfluh' and firstname='Rubbi' or kpvpartid=11147260; -- 11147260
/*
KPVPARTID  TPVPARTID  NAME        FIRSTNAME  PERSONID       VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ----------  ---------  -------------  ----------  ----------  -------------------  
11147260   11147258   Rothenfluh  Rubbi      (null)         1989-01-07  2001-01-17  2008-10-23 07:55:27  
11147260   11147303   Rothenfluh  Rubbi      (null)         2001-01-18  2007-12-31  2008-10-23 07:55:27  
11147260   11147334   Rothenfluh  Rubbi      7569861992273  2008-01-01  9999-12-31  2015-05-11 14:29:36  
*/
select * from vista.tpvaddress where kpvpartid=11147260; -- WS: 37711201
select * from vista.tbiprocessed_uow where vista_kpv_key=37711201;
/*
TBIPROCUOWID  IBMSNAP_COMMITSEQ     IBMSNAP_INTENTSEQ     VISTA_TABLE_NAME  PROCESSING_STATE  VISTA_KPV_KEY  LASTUPDATED          
------------  --------------------  --------------------  ----------------  ----------------  -------------  -------------------  
3200671133    5A81780F000000020000  000000000207CC1C0FAB  TPVADDRESS        N                 37711201       2018-02-12 12:19:01  
3206255309    5A844C4A0000000E0000  00000000020B5A5F1EC2  TPVADDRESS        N                 37711201       2018-02-14 15:49:12  
3218774254    5A8D71E3000000020000  000000000214D8E8BCA6  TPVADDRESS        N                 37711201       2018-02-21 14:20:05  
*/


-- 177267 - SO - IG_PV_DELA_V nicht produziert in prodSO (aber in EduSO)
select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 10 days and f.HDR_IDE like 'IG_PV_DELA_V';
-- PROD:
/*
REC_IDE              HDR_IDE       PROD_STATE  CREATETIME           DESCRIPTION   
-------------------  ------------  ----------  -------------------  ------------  
1812808540006336711  IG_PV_DELA_V  S           2018-05-08 08:54:13  IG_PV_DELA_V  
1812808540006336714  IG_PV_DELA_V  S           2018-05-08 08:54:26  IG_PV_DELA_V  
1812810250006337105  IG_PV_DELA_V  S           2018-05-08 10:25:08  IG_PV_DELA_V  
1812810250006337107  IG_PV_DELA_V  S           2018-05-08 10:25:43  IG_PV_DELA_V  
1812814430006338184  IG_PV_DELA_V  S           2018-05-08 14:43:43  IG_PV_DELA_V  
1812814430006338186  IG_PV_DELA_V  S           2018-05-08 14:43:50  IG_PV_DELA_V  
1812906050006340352  IG_PV_DELA_V  S           2018-05-09 06:05:40  IG_PV_DELA_V  
1812906280006340291  IG_PV_DELA_V  S           2018-05-09 06:28:14  IG_PV_DELA_V  
1812908570006340918  IG_PV_DELA_V  S           2018-05-09 08:57:53  IG_PV_DELA_V  
1813115040006346693  IG_PV_DELA_V  S           2018-05-11 15:04:15  IG_PV_DELA_V  
*/
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in '1813115040006346693'
--and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID')
with ur;
/*
REC_IDE              PARMNAME               VALUE     
-------------------  ---------------------  --------  
1813115040006346693  IG_EXPRESSDRUCK        J         
1813115040006346693  IG_VERARBEITUNGSDATUM  20180511  
1813115040006346693  DOPDOCSTAT             NEW       
1813115040006346693  IG_ELAR_PID            2935140            
*/
-- EDU:
select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 10 days and f.HDR_IDE like 'IG_PV_DELA_V';
/*
REC_IDE              HDR_IDE       PROD_STATE  CREATETIME           DESCRIPTION   
-------------------  ------------  ----------  -------------------  ------------  
1812908340006216486  IG_PV_DELA_V  F           2018-05-09 08:34:46  IG_PV_DELA_V  
1812908360006216491  IG_PV_DELA_V  F           2018-05-09 08:36:11  IG_PV_DELA_V  
*/
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in '1812908360006216491'
and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID')
with ur;
/*
REC_IDE              PARMNAME               VALUE           
-------------------  ---------------------  --------------  
1812908360006216491  IG_ELAR_PID            3999081         
1812908360006216491  IG_VERARBEITUNGSDATUM  20180509        
1812908360006216491  IG_EXPRESSDRUCK        J               
1812908360006216491  DOPDOCSTAT             FINISHED        
1812908360006216491  DOPDOCID               IG_PV_DELA_V    
1812908360006216491  OS_PROCESSINGDATE      20180509083555  
1812908360006216491  IG_EXPRESSDRUCK        J               
1812908360006216491  DOPDOCSTAT             FINISHED                                                          
*/
-- PROD SG: --1813511280014763319
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in '1813511280014763319'
and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID')
with ur;
/*
REC_IDE              PARMNAME               VALUE           
-------------------  ---------------------  --------------  
1813511280014763319  IG_ELAR_PID            1849985         
1813511280014763319  IG_VERARBEITUNGSDATUM  20180515        
1813511280014763319  IG_EXPRESSDRUCK        J               
1813511280014763319  DOPDOCSTAT             FINISHED        
1813511280014763319  DOPDOCID               IG_PV_DELA_V    
1813511280014763319  OS_PROCESSINGDATE      20180515112816  
1813511280014763319  IG_EXPRESSDRUCK        J               
1813511280014763319  DOPDOCSTAT             FINISHED        
*/

select * from vista.tbiprocessed_uow;

select * from vista.tpvpartner where kpvpartid=2935140;
select * from vista.tpvrole where kpvpartid=2935140;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
2935154    2935162    2935140    Rolle#STA  (null)     (null)       (null)  1934-12-22  9999-12-31  2011-08-31 14:11:13  
47181915   47181916   2935140    Rolle#HE   (null)     (null)       (null)  1900-01-01  9999-12-31  2012-03-27 02:21:12  
47962663   47962664   2935140    Rolle#RE   (null)     (null)       (null)  1934-12-22  9999-12-31  2012-03-27 02:25:30  
63523367   63523368   2935140    Rolle#IK   (null)     (null)       (null)  1934-12-22  9999-12-31  2012-03-27 03:57:22  
188617004  188617005  2935140    Rolle#VB   (null)     (null)       (null)  1934-12-22  9999-12-31  2013-03-18 20:56:25  
285807985  285807986  2935140    Rolle#EL   (null)     (null)       (null)  1900-01-01  9999-12-31  2014-07-22 15:33:14  
*/
select c.code_id, c.codeno, c.shortcode, c.const_field, c.value, d.short_descript,
attr.code_id, attr.value
from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode rel on (rel.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = rel.code1)
where c.code_id like 'Rolle%' and attr.code_id = 'VATTRVALS#addrDelWarn'
order by c.shortcode;
/*
CODE_ID      CODENO    SHORTCODE   CONST_FIELD  VALUE          SHORT_DESCRIPT                  CODE_ID                VALUE  
-----------  --------  ----------  -----------  -------------  ------------------------------  ---------------------  -----  
Rolle#AB     42008469  AB          ROLLE_AB     BusinessAp#BW  AB                              VATTRVALS#addrDelWarn  Y      
Rolle#AG     42008526  AG          ROLLE_AG     BusinessAp#BW  AG                              VATTRVALS#addrDelWarn  Y      
Rolle#BGSA   42008583  BGSA        ROLLE_BGSA   BusinessAp#BW  BGSA                            VATTRVALS#addrDelWarn  Y      
Rolle#IV     42022792  IV          ROLLE_IV     BusinessAp#IV  IV                              VATTRVALS#addrDelWarn  Y      
Rolle#IVTGB  42301481  IVTGB       ROLLE_IVTGB  BusinessAp#IT  IVTGB                           VATTRVALS#addrDelWarn  Y      
Rolle#NE     42008697  NE          ROLLE_NE     BusinessAp#BW  NE                              VATTRVALS#addrDelWarn  Y      
Rolle#SE     42008640  SE          ROLLE_SE     BusinessAp#BW  SE                              VATTRVALS#addrDelWarn  Y      
Rolle#ST     42008754  ST          ROLLE_ST     BusinessAp#BW  ST                              VATTRVALS#addrDelWarn  Y      
Rolle#VB     42008923  VB          ROLLE_VB     BusinessAp#VB  VB                              VATTRVALS#addrDelWarn  Y      
*/
select * from vista.tiscmcode where code_id like 'PVCONST%';


-- 177807 - ZG - Bank mit einem neuen Bankenstamm Clearingnr = 8800
select * from vista.tpvbankbasic where clearingnr='8800'; -- 2448871
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME                          ADDRESS1    ADDRESS2  ZIP     CITY   BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  --------------------------------  ----------  --------  ------  -----  --------  ----------  ----------  ----------  -------------------  
2448869    2448871    (null)   8800        Liechtensteinische Landesbank AG  Stdtle 44  (null)    949000  Vaduz  0         Country#LI  1900-01-01  9999-12-31  2018-05-16 11:23:56  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=2448871;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
4439143      2448869        2448871        2007-02-19        9999-12-31      TPVBANKBASIC      0                         TFIRMA              412394461905163  2007-02-19 12:23:39  2009-03-05 00:04:30  
*/


-- 177488 - ZH - Abr.-Nr. nicht im System (GF ohne Indexwerte)
select * from vista.tikemployerarchive where billnbr='VD1790';


-- 178040 - SH - PVJ
select * from vista.tpvemployee order by shortname asc;

select distinct(csz) from vista.tikcollection;

select * from vista.tpvaddressbasic where ccountry='Country#LI' order by street;

select * from vista.tpvaddress order by lastupdated desc; -- 9000010001051024 (Knobloch) - IT301
select * from vista.tpvrole where kpvpartid=9000010001051024; -- Rolle#IV --> BW

select * from vista.tpvpartner where temp='Y';
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and temp is null;
select * from vista.tpvpartner where kpvpartid=999991000000002;
select * from vista.tpvaddressbasic;


SELECT p.kpvpartid, p.name, p.firstname, rr.kpvrrelid, rr.crelationtype, ab.kpvadbaid, ab.zip, ab.street, ab.validto as ab_validto, RR.VALIDTO as rr_validto FROM VISTA.TPVPARTNER p
LEFT JOIN vista.tpvaddress a ON (a.kpvpartid=p.kpvpartid)
LEFT JOIN vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
LEFT JOIN vista.TPVROLEREL RR ON (RR.KPVADRSID_CORR = a.KPVADRSID )
WHERE kpvrrelid is not null and ab.validto < current date 
and not exists (select 1 from vista.tpvaddressbasic ab2 where ab2.kpvadbaid = ab.kpvadbaid and ab2.validto > current date);

select * from vista.tpvaddressbasic where kpvadbaid=60894;

select a.kpvadrsid, a.validto from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where a.validto > current date
and not exists (select 1 from vista.tpvaddressbasic ab2 where ab2.kpvadbaid = ab.kpvadbaid and ab2.validto > current date);


SELECT a.kpvpartid, RR.VALIDTO  FROM VISTA.TPVADDRESS a
LEFT JOIN vista.TPVROLEREL RR on (RR.KPVADRSID_CORR = a.KPVADRSID and RR.validto >= current date)
LEFT JOIN vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
WHERE ab.VALIDTO < current date;


-- 178813 - NW - Postkorb ohna Abr.-Nr.
/*
@Gerry: der Partner hat drei EintrÃƒÂ¤ge im IK-Kurzregister, mit 3 verschiedenen Abr.-Nr.,
Vermutung: der Service gibt nix zurÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼ck, wenn der Treffer nicht eindeutig ist. Korrekt?
*/
select p.kpvpartid, p.name, p.validfrom as p_validfrom, p.validto as p_validto, keym.edv2000_zid_key, 
ea.tikearcid, ea.billnbr, ea.adr1, ea.uid, ea.edv2000partnerid, ea.validfrom as ea_validfrom, ea.validto as ea_validto from vista.TPVPARTNER p
join vista.TPVELARPID elar on elar.KPVPARTID = p.KPVPARTID
join vista.TBIKEYMAPPING2000 keym on keym.VISTA_KPV_KEY = p.KPVPARTID
join vista.TIKEMPLOYERARCHIVE ea on ea.EDV2000PARTNERID = keym.EDV2000_ZID_KEY
where p.NAME like 'Pilatus%'
and elar.ELARPID = '000000000014467'
and keym.VISTA_TABLE_NAME = 'TPVPARTNER';


-- 179076 - ZH - IVTG: alte AHV-Nr. fehlt in EDV2000
select * from vista.tbikeymapping2000 where edv2000_zid_key=186113635602316; -- kpvpartid = 10732528
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME   VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  -----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
82869852     82737898       82737899       2010-01-01        2016-12-31      TPVTAXDATA         0                         TSTEUERDOMIZIL      186113635602316  2016-06-06 08:44:37  2016-06-06 08:45:55  
50182607     10732527       10732528       1999-05-05        2001-03-13      TPVEDV2000PARTNER  0                         TPARTNER            186113635602316  2008-10-23 07:49:53  2008-10-23 20:30:38  
50182609     10732568       10732528       2001-03-14        9999-12-31      TPVEDV2000PARTNER  0                         TPARTNER            186113635602316  2008-10-23 07:49:54  2008-10-23 20:30:38  
50182610     10732568       10732528       1998-11-28        9999-12-31      TPVPARTNER         0                         TPERSON             186113635602316  2018-05-15 13:19:10  2018-05-15 13:19:31  
50182611     10732568       10732528       1998-11-28        9999-12-31      TPVSOCIALSECNBR    0                         TVERSICHERTENNR     186113635602316  2018-05-15 13:19:10  2018-05-15 13:19:31  
57062968     27137748       10732528       1900-01-01        9999-12-31      TPVFAMILYREL       0                         TELTERNSCHAFT       186113635602316  2001-03-14 23:01:40  2008-10-23 20:30:38  
57229346     27470489       10732528       1900-01-01        9999-12-31      TPVFAMILYREL       0                         TELTERNSCHAFT       186113635602316  1999-05-05 10:06:36  2008-10-23 20:30:38  
2266722656   2266096003     82737899       2017-01-01        2017-12-31      TPVTAXDATA         0                         TSTEUERDOMIZIL      186113635602316  2017-06-27 14:45:44  2017-06-27 14:45:55  
2848683652   2848666882     82737899       2018-01-01        2018-12-31      TPVTAXDATA         0                         TSTEUERDOMIZIL      186113635602316  2018-05-09 16:42:51  2018-05-09 16:43:05  
3331832684   3331820658     82737899       2019-01-01        9999-12-31      TPVTAXDATA         0                         TSTEUERDOMIZIL      186113635602316  2018-05-09 16:42:51  2018-05-09 16:43:05  
*/
select * from vista.tbiprocessed_uow where vista_kpv_key=10732528;
/*
TBIPROCUOWID  IBMSNAP_COMMITSEQ     IBMSNAP_INTENTSEQ     VISTA_TABLE_NAME  PROCESSING_STATE  VISTA_KPV_KEY  LASTUPDATED          
------------  --------------------  --------------------  ----------------  ----------------  -------------  -------------------  
3340370683    5AFAC16E000000010000  00000000028EC3B4619B  TPVPARTNER        P                 10732528       2018-05-15 13:18:07  
3340370684    5AFAC16E000000010000  00000000028EC3B471AE  TPVPARTNER        P                 10732528       2018-05-15 13:18:07  
3340370687    5AFAC17A000000010000  00000000028EC3BA1F4D  TPVPARTNER        P                 10732528       2018-05-15 13:18:37  
3340370688    5AFAC17A000000010000  00000000028EC3BA327C  TPVPARTNER        P                 10732528       2018-05-15 13:19:07  
*/
select * from vista.tpvpartner where name='Altenburger' and firstname='Nina'; -- kpvpartid = 10732528;  socialsecnr = 10998859110 in der neuesten Periode


-- 179141 - ZH - BI Replikation lÃƒÂ¤uft nicht
select * from vista.tbiprocessed_uow order by lastupdated desc;
select * from vista.tpvaddress where lastupdated > '2018-06-12 00:44:54' and lastupdated < '2018-06-12 09:44:54' order by lastupdated desc;
select distinct change_user, count(*) as cnt_user from vista.jpvaddress where change_date > '2018-06-11 20:44:54' and change_date < '2018-06-12 09:44:54' group by change_user;
/*
CHANGE_USER  CNT_USER  
-----------  --------  
ZH045        102       
ZH1076       5         
ZH1172       47        
ZH201        1         
ZH2223       18        
ZH2292       26        
ZH2394       34        
ZH2433       24        
ZH2434       29        
ZH2442       34        
ZH2444       46        
ZH2445       5         
ZH565        3         
ZH5713       4         
ZH840        39        
ZH965        3         
*/
select count(*) as cnt_n from vista.tbiprocessed_uow where processing_state='N' and lastupdated > '2018-06-12 00:44:54'; -- 230150
select distinct program, count(*) as cnt_program from vista.jpvaddress where kpvadrsid in (
    select vista_kpv_key from vista.tbiprocessed_uow where processing_state='N' and lastupdated > '2018-06-12 00:44:54'
) group by program order by count(*) desc;
/*
CHANGE_USER  CNT_USER  
-----------  --------  
DB2ADM       345549    
DKPROZH      10        
PEKREMER     36        
ZH045        642       
ZH1076       54        
ZH1097       40        
ZH1172       520       
ZH1248       194       
ZH1380       92        
ZH1448       1205      
ZH1494       739       
ZH1654       266       
*/
/*
PROGRAM                                                  CNT_PROGRAM  
-------------------------------------------------------  -----------  
CLP SetPOLG_V.01.sql                                     345426       
PV:PV-Dlg-301 Adresse                                    9431         
PV:PV-Dlg-702 Dialog Periode Adresse                     885          
PV:PV-Dlg-20409 Dialog Familien mutieren                 520          
PV:PV-Dlg-20406 Dialog Neues Kind                        258          
CLP 166114_ZH_Gemeindefusionen_v1.11_Hirzel-Horgen.sql   34           
19251949-20180301-114207 - RFS 171521                    10           
PV:PV-Dlg-20404 Familie-Adresse                          8            
CLP 163209_ZH_Gemeindefusionen_v1.9_Hofstetten-Elgg.sql  2            
PV:PV-Dlg-20408 Dialog Neuer Ehepartner                  1            
*/
select * from vista.cdtgtpvaddress;
select * from vista.tgtpvaddress;
select * from vista.cdtpvaddress;
select * from vista.tbiprocessed_uow;
select count(*) from vista.tbiprocessed_uow where lastupdated > '2018-06-09 00:00:48'; --and lastupdated < '2018-06-11 23:24:48';
select count(*) from vista.tbiprocessed_uow where lastupdated > '2018-06-09 00:00:48' and lastupdated < '2018-06-11 23:24:48';
select count(*) from vista.tbiprocessed_uow where lastupdated > '2018-06-09 00:00:48' and lastupdated < '2018-06-11 23:24:48';

select count(*) from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-08'; -- 9683
select count(*) from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-09'; -- 64725
select count(*) from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-10'; -- 182782
select count(*) from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-11'; -- 1037213
select count(*) from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-12'; -- 896514

select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09'; -- 2180363

select * from vista.tgtpvaddress;
select * from vista.tpvdynamicparams;

select count(*) from vista.tpvpartnerreplication where date(lastupdated) = '2018-06-09'; -- 287
select count(*) from vista.tpvpartnerreplication where date(lastupdated) = '2018-06-10'; -- 2
select count(*) from vista.tpvpartnerreplication where date(lastupdated) = '2018-06-11'; -- 11
select count(*) from vista.tpvpartnerreplication where date(lastupdated) = '2018-06-12'; -- 6 

select count(*) from vista.tbiprocessed_uow where lastupdated > '2018-06-13 00:00:48'; --and lastupdated < '2018-06-11 23:24:48';

select count(*) from vista.TBIINTERFACE2000 where lastupdated > '2018-06-06 00:00:48'; -- 1725739
select count(*) from vista.TBIINTERFACE2000 where lastupdated > '2018-06-13 00:00:48'; -- 257666
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) > '2018-06-09'; -- 1611384
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) >= '2018-06-09' and processing_state='P'; -- 1722319

select count(*) from vista.tbikeymapping2000 where date(lastupdated) >= '2018-06-09'; -- 1831228
select * from vista.tbikeymapping2000 where vista_table_name='TPVADDRESS' and date(lastupdated) >= '2018-06-09' order by lastupdated desc;
select count(*) from vista.tbikeymapping2000 where vista_table_name='TPVADDRESS' and date(lastupdated) >= '2018-06-09'; -- 1113410, 1114010, 1114310

select * from vista.jpvaddress where kpvadrsid in (2404936313);

select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-09'; -- 109939
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-10'; -- 292567
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-11'; -- 586297
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-12'; -- 439219
select count(*) from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-13'; -- 257256, 291509
select * from vista.TBIINTERFACE2000 where date(lastupdated) = '2018-06-13' order by lastupdated desc; -- 257256

select * from vista.tbiprocessed_uow where date(lastupdated) = '2018-06-13' order by lastupdated desc;

select * from vista.tbiprocessed_uow where date(lastupdated) > '2018-06-09' and processing_state='X' order by lastupdated desc;
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state='X'; -- 683155
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state<>'X'; -- 1887208
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state not in ('X', 'P', 'E'); -- 792918
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-13' and processing_state not in ('X', 'P', 'E'); -- 400122, 480028
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-13' and processing_state in ('N'); -- 400104, 420055, 420019, 420032
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state in ('N'); -- 800823, 835386, 1519478
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and date(lastupdated) <= '2018-06-11' and processing_state in ('N'); -- 12

select count(*) from vista.tgtpvaddress where date(lastupdated) >= '2018-06-09'; -- 3589029, 3589039
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09'; -- 2670363, 2670363, 2677863, 2690363, 2710363, 2720363, 2970363 (14.06.2018, 09:57), 3262863
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state in ('N'); -- 847015, 849549, 858994
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state in ('P'); -- 1150493
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state in ('X'); -- 683155
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-09' and processing_state in ('O'); -- 0


select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 13:00:00' and lastupdated <= '2018-06-13 14:00:00' and processing_state in ('N'); -- 60000
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 14:00:00' and lastupdated <= '2018-06-13 15:00:00' and processing_state in ('N'); -- 60000
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 10:00:00' and lastupdated <= '2018-06-13 11:00:00' and processing_state in ('N'); -- 60000
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 10:00:00' and lastupdated <= '2018-06-13 11:00:00' and processing_state in ('N'); -- 60000

select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-12 10:00:00' and lastupdated <= '2018-06-12 11:00:00' and processing_state in ('N'); -- 20526
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-11 10:00:00' and lastupdated <= '2018-06-11 11:00:00' and processing_state in ('N'); -- 0
-- Nachtverarbeitung mit Special:
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 22:00:00' and lastupdated <= '2018-06-13 23:00:00' and processing_state in ('N'); -- 0
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-13 23:00:00' and lastupdated <= '2018-06-13 23:59:59' and processing_state in ('N'); -- 70000
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-14 00:00:00' and lastupdated <= '2018-06-14 01:00:00' and processing_state in ('N'); -- 10000
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-14 01:00:00' and lastupdated <= '2018-06-14 02:00:00' and processing_state in ('N'); -- 0
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-14 02:00:00' and lastupdated <= '2018-06-14 03:00:00' and processing_state in ('N'); -- 0

select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-14 23:00:00' and lastupdated <= '2018-06-14 23:59:59' and processing_state in ('N'); -- 141163

-- Tagesverarbeitung Freitag:
select count(*) from vista.tbiprocessed_uow where vista_table_name = 'TPVADDRESS' and lastupdated >= '2018-06-15 02:00:00' and lastupdated <= '2018-06-15 03:00:00' and processing_state in ('N'); -- 0




select count(*) from vista.tbiprocessed_uow uow
where date(uow.lastupdated) >= '2018-06-09'
and date(uow.lastupdated) <= '2018-06-11'
and uow.vista_table_name = 'TPVADDRESS'
and uow.processing_state='N';

select * from vista.tbiprocessed_uow uow
where date(uow.lastupdated) >= '2018-06-09'
and date(uow.lastupdated) <= '2018-06-11'
and uow.vista_table_name = 'TPVADDRESS'
order by lastupdated desc;

select * from vista.tgtpvaddress
where date(lastupdated) >= '2018-06-09'
and date(lastupdated) <= '2018-06-10'
order by lastupdated desc;
/*
TPVADRSID   KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1                       APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR                        LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     LASTUPDATED          XSECTOR                       IBMSNAP_COMMITSEQ     IBMSNAP_INTENTSEQ     IBMSNAP_OPERATION  IBMSNAP_LOGMARKER    IBMSNAP_AUTHID  
----------  ---------  -------------------  ---------  ---------  -------------  ------------------------------  ---------  ------------  --------  -------------  ----------------------------  ------  -------------  ------------  ----------  ----------  -------------------  ----------------------------  --------------------  --------------------  -----------------  -------------------  --------------  
28713262    16627037   964680               257812     28713266   AddressTyp#WS  (null)                          (null)     AppendixPo#V  5         5              (null)                        N       AddressStr#CH  (null)        1999-01-01  9999-12-31  2018-06-09 09:31:57  (null)                        5B1B826D0000002F0000  0000000002B8B6247862  U                  2018-06-09 09:31:57  DB2ADM          
36362541    16627090   964790               629579     36362542   AddressTyp#WS  (null)                          (null)     AppendixPo#V  18        18             (null)                        N       AddressStr#CH  (null)        1904-02-26  9999-12-31  2018-06-09 09:31:57  (null)                        5B1B826D000000300000  0000000002B8B6247D60  U                  2018-06-09 09:31:57  DB2ADM          
(...)
*/
select count(*) from vista.tgtpvaddress
where date(lastupdated) >= '2018-06-09'
and date(lastupdated) <= '2018-06-10'; -- 3582872

select * from vista.tbiprocessed_uow where IBMSNAP_COMMITSEQ=x'5B1B826D0000002F0000'; -- empty
select * from vista.tbiprocessed_uow where vista_table_name='TPVADDRESS' order by lastupdated desc;
/*
TBIPROCUOWID  IBMSNAP_COMMITSEQ     IBMSNAP_INTENTSEQ     VISTA_TABLE_NAME  PROCESSING_STATE  VISTA_KPV_KEY  LASTUPDATED          
------------  --------------------  --------------------  ----------------  ----------------  -------------  -------------------  
3394715101    5B1B7A30000002AC0000  0000000002B831EB3023  TPVADDRESS        P                 37011654       2018-06-14 15:48:52  
3394715100    5B1B7A30000002AB0000  0000000002B831EB2B0B  TPVADDRESS        P                 29551703       2018-06-14 15:48:52  
(...)
*/
--> Neuen Eintrag in TBIPROCESSED_UOW schreiben mit letzter Commit/Intent-Sequence:
insert into vista.tbiprocessed_uow values (nextval for vista.vista_seq, x'5B1B826D0000002F0000', x'0000000002B8B6247862', 'TPVADDRESS', 'X', 28713266, current timestamp);
--> Bisherig erstellte Eintrge in TBIPROCESSED_UOW vom Wochenende auf X setzen?
select count(*) from vista.tbiprocessed_uow uow
where date(uow.lastupdated) >= '2018-06-09'
and uow.vista_table_name = 'TPVADDRESS'
and uow.vista_kpv_key in (
    select kpvadrsid from vista.tgtpvaddress
    where date(lastupdated) >= '2018-06-09'
    and date(lastupdated) <= '2018-06-10'
)
and uow.processing_state='N'; -- 1282775, 1452194
--> Update...
update vista.tbiprocessed_uow uow set uow.processing_state='X'
where date(uow.lastupdated) >= '2018-06-09'
and uow.vista_table_name = 'TPVADDRESS'
and uow.vista_kpv_key in (
    select kpvadrsid from vista.tgtpvaddress
    where date(lastupdated) >= '2018-06-09'
    and date(lastupdated) <= '2018-06-10'
)
and uow.processing_state='N';


select * from vista.jpvaddress where kpvadrsid=1191125774;
select count(*) from vista.tbikeymapping2000 where edv2000_zid_key is null and date(lastupdated) = '2018-06-09';  -- 31508

-- 174921 - ZH - Familienbeziehung nicht in EDV2000
select * from vista.tpvpartner where kpvpartid=14614622; -- Friedrich Schaubeck, 7564853676421
select * from vista.tpvfamilyrel where kpvpartid_source=14614622; -- empty
select * from vista.tpvfamilyrel where kpvpartid_target=14614622; -- empty

select * from vista.tpvpartner where personid='7566127421362'; -- 13451843, Frey Sylvia
select * from vista.tpvfamilyrel where kpvpartid_source=13451843; -- empty
select * from vista.tpvfamilyrel where kpvpartid_target=13451843; -- empty


-- 179109 - ZH - ELAR-Indizierung hat nicht funktioniert 
/*
Die Archivierung in ELAR durch den EAS DokumentImporter lÃƒÂ¤uft technisch korrekt. Zum Zeitpinkt der Archivierung (04.06.2018 08:15) bekommt ELAR von der Vista PV die RÃƒÆ’Ã‚Â¼ckmeldung, dass es die Abrechnungsnummer CZ9251 nicht gibt. Darum wird durch ELAR temporr indiziert.
04.06.18 08:15:10.77: searchPartners: searchValues={{ABRNR=CZ9251},{BATCHSUCHE=1},{PHONETIC=0}}
04.06.18 08:15:10.80: searchPartnersVistaReturnValues: return={} (searchValues={{ABRNR=CZ9251},{BATCHSUCHE=1},{PHONETIC=0}})
04.06.18 08:15:10.80: searchPartners: return={} (searchValues={{ABRNR=CZ9251},{BATCHSUCHE=1},{PHONETIC=0}})

Ticket zur Analyse an Vista PV, damit geklrt werden kann, warum searchPartners diese Abrechnungsnummer nicht findet, obwohl der Kunde sagt, dass es dieses Mitglied schon seit Jahren gibt.
*/
select * from vista.tikemployerarchive where billnbr='CZ9251';
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                           ADR2        ADR3  ADR4           KPVCORRADDRESS  UID           CREGISTERCODE   CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE  LASTUPDATED          
----------  -------  ----------  -----------  -----------------------------  ----------  ----  -------------  --------------  ------------  --------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  -----------  -------------------  
1224362118  CZ9251   (null)      BRANCHE#01   Gebr. Meier GemÃƒÆ’Ã‚Â¼sekulturen AG  Erlenhof 3        8108 Dllikon  33095385        CHE108712903  ERFASSTCOD#812  RECHTSFORM#G  EADMINCODE#N  1358042052004         470714633304933   1358042052004         470714633304933           2006-01-01  9999-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2018-06-04 12:11:01  
*/
select * from vista.tikemployerarchive where edv2000partnerid=470714633304933; -- siehe oben
select * from vista.jikemployerarchive where billnbr='CZ9251';
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                           ADR2        ADR3  ADR4           KPVCORRADDRESS  UID           CREGISTERCODE   CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                  OPERATION  
----------  -------  ----------  -----------  -----------------------------  ----------  ----  -------------  --------------  ------------  --------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  -----------  -------------------  -------------------  -----------  -----------------------  ---------  
1224362118  CZ9251   (null)      BRANCHE#01   Gebr. Meier GemÃƒÆ’Ã‚Â¼sekulturen AG  Erlenhof 3        8108 Dllikon  33095385        CHE108712903  ERFASSTCOD#812  RECHTSFORM#G  EADMINCODE#N  1358042052004         470714633304933   1358042052004         470714633304933           2006-01-01  9999-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2016-07-26 12:12:41  2018-05-30 17:11:02  ZHIK0A01     IK:IKJIMPBWD:3359658522  U          
1224362118  CZ9251   (null)      BRANCHE#01   Gebr. Meier GemÃƒÆ’Ã‚Â¼sekulturen AG  Erlenhof 3        8108 Dllikon  33095385        CHE108712903  ERFASSTCOD#812  RECHTSFORM#G  EADMINCODE#N  1358042052004         470714633304933   1358042052004         470714633304933           2006-01-01  9999-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2018-05-31 07:13:40  2018-05-31 07:13:40  ZHIK0A01     IK:IKJIMPBWD:3360876847  U          
*/
select * from vista.jikemployerarchive where tikearcid=1224362118;

select * from vista.tpvpartner p
left join vista.tbikeymapping2000 bi on (bi.vista_kpv_key=p.kpvpartid and bi.vista_table_name='TPVPARTNER')
where bi.edv2000_zid_key=470714633304933;
/*
TPVPARTID  KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE    SOCIALSECNR  TITEL   NAME                           NAMESX  UPPERNAME                      FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE  BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE      CLEGALFORM     CSEX    ADDITIONALNAME  UPPERADDITIONALNAME  CCANTON  COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID  CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS  TEMP  ISVIC  VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
---------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  --------------  -----------  ------  -----------------------------  ------  -----------------------------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ---------  -------------  ------------  ----------------  ------------  --------------  -------------  ------  --------------  -------------------  -------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  --------  -----------  --------------  ----------------  --------------------  ------------  ----------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  -------  ----  -----  ----------  ----------  --------  -------------  -------------------  -----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
25865513   25865520   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NNP  (null)       (null)  Gebr. Meier GemÃƒÆ’Ã‚Â¼sekulturen AG  G165    GEBR. MEIER GEMÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¢ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬Ãƒâ€¦Ã‚Â¡ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¦ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¢Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¡ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬Ãƒâ€¦Ã‚Â¡ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÆ’Ã…â€œSEKULTUREN AG  (null)     (null)       (null)          (null)    (null)         (null)     (null)          (null)         CorresLang#D  (null)     (null)         (null)        (null)            Protection#0  NNPersonTy#NNP  LegalFormC#AG  (null)  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        (null)        (null)            (null)    (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       (null)   N     N      1900-01-01  9999-12-31  (null)    (null)         2008-10-23 11:12:03  56552927     25865513       25865520       1900-01-01        9999-12-31      TPVPARTNER        0                         TFIRMA              470714633304933  2018-05-30 17:09:55  2018-05-30 17:10:18  
*/

-- Repro auf IT401

select * from vista.tpvbankbasic;


-- 179611 - ZH - BI lÃƒÂ¤uft wieder nicht
select * from vista.jpvaddress where date(lastupdated) = '2018-06-19';

select * from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-21' and processing_state='N' order by lastupdated desc;
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-21' and processing_state='N'; -- 68
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-21' and processing_state<>'N'; -- 3845
select count(*) from vista.tbiprocessed_uow where date(lastupdated) >= '2018-06-21' and processing_state in ('X', 'P', 'E'); -- 3837

select count(*) from vista.tgtpvpartner where date(lastupdated) >= '2018-06-21'; -- 1783
select * from vista.tgtpvpartner where date(lastupdated) >= '2018-06-21'; -- 1783
select count(*) from vista.tgtpvpartner where date(lastupdated) = '2018-06-20'; -- 6051
select count(*) from vista.tgtpvaddress where date(lastupdated) >= '2018-06-21'; -- 522
select count(*) from vista.tgtpvaddress where date(lastupdated) = '2018-06-20'; -- 1972

select count(*) from vista.tbikeymapping2000 where date(lastupdated) >= '2018-06-21' and vista_table_name='TPVPARTNER'; -- 946
select count(*) from vista.tbikeymapping2000 where date(lastupdated) >= '2018-06-21' and vista_table_name='TPVADDRESS'; -- 475



select * from vista.tiscmcode where shortcode like 'Rolle%';
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Rolle%'
order by c.value;


-- Defect 7603: Civilstate consolidation in replication
select kpvpartid, birthdate, ccivilstatus, civilstatussince, cseparation, separationdate, validfrom, validto from vista.tpvpartner 
where kpvpartid in (select kpvpartid from vista.tpvpartner where separationdate is not null) order by kpvpartid, validfrom asc; -- AIT401: 30041

select kpvpartid, birthdate, ccivilstatus, civilstatussince, cseparation, separationdate, validfrom, validto from vista.tpvpartner 
where kpvpartid in (9500000000323109) order by kpvpartid, validfrom asc; -- AIT401: 30041

select * from vista.tpvpartner;

-- Not working cases: 30041, 30174
-- Working cases: 9000010001050001, 999991004142500, 167885403

select * from vista.tsfmqinbound where lastupdated>'2018-06-26 08:17:03' and jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqoutbound where lastupdated>'2018-06-26 08:17:03' and jmstype='BZ.PV-I003' order by lastupdated desc;

select * from vista.tbdpostfilestreet where polgcanton='FL';
select * from vista.tbdpostfilezip where canton='FL';


select * from vista.tikemployerarchive where billnbr='10010003916';
/*
TIKEARCID  BILLNBR      BILLNBROLD  CBRANCHCODE  ADR1        ADR2  ADR3  ADR4                 KPVCORRADDRESS  UID     CREGISTERCODE  CLEGALFORM  CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE  LASTUPDATED          
---------  -----------  ----------  -----------  ----------  ----  ----  -------------------  --------------  ------  -------------  ----------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  -----------  -------------------  
22198539   10010003916  3010901201  BRANCHE#01   Altersheim              876200 Schwanden GL  (null)          (null)  (null)         (null)      EADMINCODE#N  24644                 11206             16250                 (null)                    1948-01-01  1980-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2012-01-24 00:06:18  
*/
select * from vista.tikemployerarchive;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'BRANCHE%'
order by c.value;
/*
CODE_ID     SHORTCODE   VALUE  LONG_DESCRIPT                                                                                                                        
----------  ----------  -----  -----------------------------------------------------------------------------------------------------------------------------------  
BRANCHE#00  00                 AKGL intern                                                                                                                          
BRANCHE#01  01                 Landwirtschaft, Jagd und damit verbundene Ttigkeiten                                                                                
BRANCHE#01  01                 Landwirtschaft                                                                                                                       
BRANCHE#02  02                 Forstwirtschaft und Holzeinschlag                                                                                                    
BRANCHE#02  02                 Aerzte                                                                
*/

-- AIT301:
-- 1)
select * from vista.tikemployerarchive; -- 651133 / ZID=1051080
select * from vista.tbikeymapping2000 where edv2000_zid_key=1051080; -- 9000010001200704
select * from vista.tpvrole order by lastupdated desc; -- 12899
-- 2)
select * from vista.tikemployerarchive; -- 10010302085 / ZID=1051190
select * from vista.tbikeymapping2000 where edv2000_zid_key=1051190; -- 9000010001200814
select * from vista.tpvrole order by lastupdated desc; -- 12906

select * from vista.tpvaddress; -- 10367

-- Fehlermeldung:
select * from vista.tikemployerarchive where billnbr in ('10010027636', '10010010692');
/*
TIKEARCID  BILLNBR      BILLNBROLD    CBRANCHCODE  ADR1                                    ADR2  ADR3              ADR4               KPVCORRADDRESS  UID     CREGISTERCODE  CLEGALFORM  CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -----------  ------------  -----------  --------------------------------------  ----  ----------------  -----------------  --------------  ------  -------------  ----------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  ------------  -------------------  
70006116   10010027636  732360008061  BRANCHE#61   Raiffeisen BÃƒÆ’Ã‚Â¼rgschafts- Genossenschaft        Vadianstrasse 17  900000 St. Gallen  (null)          (null)  (null)         (null)      EADMINCODE#N  156404                91957             124199                (null)                    1948-01-01  1980-12-31  (null)         10763610    (null)          13890552            (null)        51395385  MEMBERTYP#AK  2018-03-02 07:48:00  
*/
-- Keine Anzeige:
select * from vista.tikemployerarchive where billnbr in ('10010027636');
select * from vista.tikemployerarchive where edv2000partnerid=133363235306182;
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                            ADR2             ADR3  ADR4                 KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -------  ----------  -----------  ------------------------------  ---------------  ----  -------------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
597072526  342717   (null)      BRANCHE#84   Gemeinde Wildhaus-Alt St. Joha  Hauptstrasse 40        9656 Alt St. Johann  48249947        CHE115050852  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#N  70837                 133363235306182   28123                 133363235306182           1948-01-01  9999-12-31  a8cf29d2-4bd2-44e7-bd55-ebc4e2eee1ee  45654862    45654862        45655005            SONDERFALL#03  45654862  MEMBERTYP#AK  2018-03-01 18:10:24  
*/


select p.kpvpartid, p.name, p.validfrom, p.validto, ea.billnbr from vista.tpvpartner p
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NNP'
and exists (
    select 1 from vista.tpvrole r where r.kpvpartid = p.kpvpartid and r.croletype='Rolle#AG'
);
-- select * from vista.tikemployerarchive where billnbr in ('10010027636');
select * from vista.tpvpartner where kpvpartid=45654862;
select * from vista.tbikeymapping2000 where vista_kpv_key=45654862; --133363235306182

select * from vista.tpvrole where kpvpartid='10557119';


select p.kpvpartid, p.name, p.validfrom, p.validto, ea.* from vista.tpvpartner p
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NNP'
and exists (
    select 1 from vista.tpvrole r where r.kpvpartid = p.kpvpartid and r.croletype='Rolle#AG'
)
and p.name='Wirkstatt Hengarten';

select p.kpvpartid, p.name, p.validfrom, p.validto, ea.* from vista.tpvpartner p
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NNP'
and exists (
    select 1 from vista.tpvrole r where r.kpvpartid = p.kpvpartid and r.croletype='Rolle#AG'
)
and p.name='Hamar GmbH';

select * from vista.tpvpartner;

select * from vista.tpvpartner with UR;

select * from migration.tdmpvpartner;
call MIGRATION.PPV_CLEAN_MIGRATION;
call MIGRATION.PPV_CLEAN_VISTA;

select distinct locked from vista.tpvaddress;
select * from vista.tpvaddress;

select distinct(temp) from vista.tpvpartner;

-- Defect 8163_ZIK-RÃƒÆ’Ã‚Â¼ckgngigmachungen nicht mehr mÃƒÆ’Ã‚Â¶glich (terminierte SZ)
/*
P.12.46.003 / SIT-401 / ZH / 10.07.2018 / igsga

Regressionstestfall: Kasseneigener Renten-ZIK SZ71 RÃƒÆ’Ã‚Â¼ckgngigmachung:
Die RÃƒÆ’Ã‚Â¼ckgngigmachungen funktionieren nicht mehr.
Es erscheint immer eine Fehlermeldung. Bzw. bei den 11-stelligen VNR erscheint eine andere Fehlermeldung (siehe weiter unten) 
*/

-- CASE 01 -------------------------------------------
/*
13 digit NNSS:
New status is not valid Message Code: IKACC00603
*/
select * from vista.aurupiregister where new_nnss='7561111667528';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME          GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
591500847         74348211114      7561111667528  0         0            RIEDER,HEINZ  1         11041948  100            (null)    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
595228552         7561111667528    7561111667528  0         1            RIEDER,HEINZ  1         11041948  100            950000    (null)     2              (null)             19021971           (null)         2018-07-04 15:04:38  
595228553         7561111667528    7561111667528  0         0            RIEDER,HEINZ  1         11041948  100            950000    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
595228554         7561111667528    7561111667528  0         0            RIEDER,HEINZ  1         11041948  100            970000    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
*/
select * from vista.tikheader where vnr='7561111667528' or tikownrid=401742842;
/*
TIKHEADID  TIKOWNRID  VNR            NAME          BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
406543882  401742842  7561111667528  RIEDER,HEINZ  1948       4           11        SEXCODEZAS#1  BSVLAND#100  74348211114    F                2016-01-19 20:33:34  
415008623  401742842  74348211114    RIEDER,HEINZ  1948       4           11        SEXCODEZAS#1  BSVLAND#100                 F                2011-09-24 19:46:59  
*/
select * from vista.tikowner where tikownrid=401742842;
/*
TIKOWNRID  KPVROLEID  LASTUPDATED          
---------  ---------  -------------------  
401742842  379886082  2011-09-24 17:54:24  
*/
select * from vista.tikaccount where tikheadid=406543882;
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE             CSTATE      CZIKREASON  ZIKAK  ZIKBO  ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  -------------------  ----------  ----------  -----  -----  --------------  -------------------  
417944219  406543882  ACCTYPE#IK    2014          SZMZR#67         AUT. WIEDEREROEFFN.  IKSTATUS#W  SZMZR#71    1      0      2012-12-01      2014-05-14 20:41:02  
*/
select * from vista.tikzikrequest where kpvroleid=379886082 or vnrla='7561111667528'; -- empty
select * from vista.tikzikorder where tikheadid=406543882 or vnr='7561111667528';
/*
TIKZIORID  TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE             VNR            VNRNAME       VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME     CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
---------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  -------------------  -------------  ------------  -------------  ----------------  -----------  ------------------  --------------  -------------  ------------  ----------------------  -----------------------  -------------------  
518068009  (null)             406543882  2011-03-22  SZMZR#97  1           0           0               1           0           IK MHU               7561111667528  RIEDER,HEINZ  (null)         2011-03-23        2011-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:55:44  
936378457  (null)             406543882  2013-03-20  SZMZR#71  1           0           0               1           0           VL 2.3 VOG 20.03.13  7561111667528  RIEDER,HEINZ  (null)         2013-03-21        2012-12-01   ZAS                 WOHNSITZ#1      7561111667528  RIEDER,HEINZ  (null)                  (null)                   2013-03-22 20:54:02  
*/
select * from vista.tikzikexecution where vnr='7561111667528' or tikziorid in (518068009, 936378457);
/*
TIKZEXCID  TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME       BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
---------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  ------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
542120061  518068009  (null)           (null)           528216478         2011-03-24        0            0                    1      0      7561111667528  RIEDER,HEINZ  0                        0                      0               2011-03-24     RH59C       1          2011-03-24    (null)                        2011-09-25 18:46:13  
936372139  936378457  (null)           (null)           936372140         2013-03-22        0            0                    1      0      7561111667528  RIEDER,HEINZ  0                        0                      0               2013-03-22     ZHIK0A01    1          2013-03-21    0                             2013-03-22 21:47:11  
*/
select * from vista.tikrequestheader where pendvnr='7561111667528'; -- empty
select * from vista.tikinsurancerequest where customer=379886082; -- empty
select * from vista.tikcollection where tikcollid in (528216478, 936372140);
/*
TIKCOLLID  TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE             CSZ       VNR            VNRNAME       VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE    ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  LASTUPDATED          
---------  ---------  ----------  ----------  ----------  -------------------  --------  -------------  ------------  -------------  -----------  -------------  ------------  ----------------  ---------  -------------------  ---------  -------------------  
528216478  406543882  2011-03-22  1           0           IK MHU               SZMZR#97  7561111667528  RIEDER,HEINZ                 (null)       7561111667528  2011-03-23    2011-03-25        (null)     (null)               (null)     2011-09-25 16:39:09  
936372140  406543882  2013-03-20  1           0           VL 2.3 VOG 20.03.13  SZMZR#71  7561111667528  RIEDER,HEINZ  (null)         2012-12-01   7561111667528  2013-03-21    (null)            (null)     VDR6515020004460263  (null)     2013-03-22 20:47:04  
*/

select * from vista.tikbooking where tikacctid=417944219;
/*
TIKBOOKID   TIKBOOKID_STORNO  TIKACCTID  TIKBOPEID   TIKINRETID  TIKBOOKID_REBOOKED  TIKCTCAID  BNOCHECKCODE  BOOKINGDATE  BILLNBR      INCOME     CCONTRIBUTIONTYPE  CCARETAKINGFACTOR  NBRINSURED  PENDVNR  PENDNAME  PENDFIRSTNAME  CEMPLOYEECODE  BASYLUMCODE  BWRITEOFFCODE  BPROVCODE  BPAPERIK  NBRAK  NBRBO  BSUPPRESSEDBOOKING  SPOUSEVNR  BMANSPLITTBOOKFLTIMES  BOOKEDBY  CLASTACTION   IKLASTACTIONDATE  IKLASTACTIONBY  BPENSIONZIK  CSTORNOCODE  BIEDV2000ID       CSPECIALCODE  CCODEADS  CSECTOR  CTOWNSHIP  BWDECREEOID  BWLISTOID  BWENTRYOID  PROCESSID  LASTUPDATED          
----------  ----------------  ---------  ----------  ----------  ------------------  ---------  ------------  -----------  -----------  ---------  -----------------  -----------------  ----------  -------  --------  -------------  -------------  -----------  -------------  ---------  --------  -----  -----  ------------------  ---------  ---------------------  --------  ------------  ----------------  --------------  -----------  -----------  ----------------  ------------  --------  -------  ---------  -----------  ---------  ----------  ---------  -------------------  
475166355   (null)            417944219  475166356   430030200   (null)              (null)     0             2010-09-01   265793       60000.00   SZBEITRART#1       (null)             0           (null)                            YESNO#J        0            0              0          0         1      0      0                   (null)     0                      FZH186    IKBUCHHIST#n  2010-09-01        FZH186          1            SZSTORNO#0   231433516606453   (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2013-03-22 21:47:11  
475166358   (null)            417944219  475166359   430030280   (null)              (null)     0             2011-03-11   265793       60000.00   SZBEITRART#1       (null)             0           (null)                            YESNO#J        0            0              0          0         1      0      0                   (null)     0                      FZH186    IKBUCHHIST#n  2011-03-11        FZH186          1            SZSTORNO#0   999944826206644   (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2013-03-22 21:47:10  
805175602   (null)            417944219  805175603   806706096   (null)              (null)     0             2012-07-04   265793       69000.00   SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH186     IKBUCHHIST#n  2012-07-04        ZH186           1            SZSTORNO#0   1000000000809525  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2013-03-22 21:47:10  
873049816   (null)            417944219  873049817   875302477   (null)              (null)     0             2012-11-22   265793       69000.00   SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH1053    IKBUCHHIST#n  2012-11-22        ZH1053          1            SZSTORNO#0   1000000001171509  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2013-03-22 21:47:10  
1312026563  (null)            417944219  1312026564  1314601243  1307366270          (null)     0             2014-05-14   265793       36800.00   SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2014-05-14        ZHIK0A01        0            SZSTORNO#0   1000000003263705  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2014-05-14 20:41:03  
1312026569  (null)            417944219  1312026570  1314601243  1307366281          (null)     0             2014-05-14   265793       24000.00   SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2014-05-14        ZHIK0A01        0            SZSTORNO#0   1000000003263706  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2014-05-14 20:41:03  
1615081638  (null)            417944219  1615081639  1620503344  (null)              (null)     0             2015-02-24   265793       73200.00   SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH791     IKBUCHHIST#n  2015-02-24        ZH791           0            SZSTORNO#0   1000000004185123  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2015-02-24 11:52:38  
1797255190  (null)            417944219  1797255191  1800866825  (null)              (null)     0             2015-07-28   265793       49200.00   SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH791     IKBUCHHIST#n  2015-07-28        ZH791           0            SZSTORNO#0   1000000004678551  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2015-07-28 07:32:07  
1797255192  (null)            417944219  1797255193  1800866825  (null)              (null)     0             2015-07-28   265793       -73200.00  SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH791     IKBUCHHIST#n  2015-07-28        ZH791           0            SZSTORNO#1   1000000004678552  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2015-07-28 07:32:07  
2066849668  (null)            417944219  2066849669  2147282181  (null)              (null)     0             2016-01-15   265793       31958.00   SZBEITRART#7       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          0         1      0      0                   (null)     0                      ZH791     IKBUCHHIST#n  2016-01-15        ZH791           0            SZSTORNO#0   1000000005033975  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2016-01-15 15:58:35  
*/
select * from vista.tikperiod where tikbopeid in (select distinct tikbopeid from vista.tikbooking where tikacctid=417944219);
/*
TIKBOPEID   ENDDATE     BEGINDATE   NBRMONTHS  REFYEAR  CSPECIALITY  ENDMONTH  BEGINMONTH  TYPE  LASTUPDATED          
----------  ----------  ----------  ---------  -------  -----------  --------  ----------  ----  -------------------  
475166356   2009-12-31  2009-01-01  (null)     (null)   (null)       (null)    (null)      1     2011-09-25 05:59:15  
475166359   2010-12-31  2010-01-01  (null)     (null)   (null)       (null)    (null)      1     2011-09-25 05:59:16  
805175603   2011-12-31  2011-01-01  (null)     (null)   (null)       (null)    (null)      1     2012-07-04 13:26:16  
873049817   2012-12-31  2012-01-01  (null)     (null)   (null)       (null)    (null)      1     2012-11-22 12:38:46  
1312026564  2013-12-31  2013-05-01  (null)     (null)   (null)       (null)    (null)      1     2014-05-12 10:34:06  
1312026570  2013-04-30  2013-01-01  (null)     (null)   (null)       (null)    (null)      1     2014-05-12 10:34:06  
1615081639  2014-12-31  2014-01-01  (null)     (null)   (null)       (null)    (null)      1     2015-02-24 11:52:38  
1797255191  2014-12-31  2014-01-01  (null)     (null)   (null)       (null)    (null)      1     2015-07-28 07:32:07  
1797255193  2014-12-31  2014-01-01  (null)     (null)   (null)       (null)    (null)      1     2015-07-28 07:32:07  
2066849669  2015-04-30  2015-01-01  (null)     (null)   (null)       (null)    (null)      1     2016-01-15 15:58:35  
*/

-- CASE 02 (same person, but old AHV-Nr.) -------------------------------------------
/*
11 digit VNR:
ZIK data (Reason, AK, BO) are incomplete  Message Code: IKACC02003 
*/
select * from vista.tikaccount where tikheadid=415008623;
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE  CSTATE      CZIKREASON  ZIKAK  ZIKBO  ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  --------  ----------  ----------  -----  -----  --------------  -------------------  
428336240  415008623  ACCTYPE#IK    2003          SZMZR#63                   IKSTATUS#S  SZMZR#71    1      0      2012-12-01      2013-03-22 21:47:10  
*/
select * from vista.tikzikrequest where kpvroleid=379886082 or vnrla='74348211114'; -- empty
select * from vista.tikzikorder where tikheadid=415008623 or vnr='74348211114';
/*
TIKZIORID  TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE              VNR            VNRNAME       VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME     CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
---------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------------------  -------------  ------------  -------------  ----------------  -----------  ------------------  --------------  -------------  ------------  ----------------------  -----------------------  -------------------  
515682592  (null)             415008623  2011-03-22  SZMZR#97  1           0           0               1           0           IK MHU                74348211114    RIEDER,HEINZ  74348211       2011-03-23        2011-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682594  (null)             415008623  2001-01-08  SZMZR#97  1           1           0               1           3           FMN  567645543602930  74348211114    RIEDER,HEINZ  74348211       2001-01-09        2001-12-01   RH59C               (null)          74348211114    RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682596  (null)             415008623  2008-10-08  SZMZR#92  1           1           0               1           0           VL 3.1/LUC 8.10.      74348211114    RIEDER,HEINZ  74348211       2008-10-09        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682598  (null)             415008623  2008-10-09  SZMZR#97  1           1           0               1           0           5.1/BDO               74348211114    RIEDER,HEINZ  74348211       2008-10-10        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682600  (null)             415008623  2001-01-08  SZMZR#97  1           3           0               1           3           F/MN                  74348211114    RIEDER,HEINZ  74348211       2001-01-09        2001-12-01   RH59C               (null)          74348211114    RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682602  (null)             415008623  2008-10-09  SZMZR#97  1           3           0               1           0           5.1/BDO               74348211114    RIEDER,HEINZ  74348211       2008-10-10        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682604  (null)             415008623  2008-10-08  SZMZR#92  1           3           0               1           0           VL 3.1/LUC 8.10.      74348211114    RIEDER,HEINZ  74348211       2008-10-09        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682606  (null)             415008623  2011-03-22  SZMZR#97  1           3           0               1           0           IK MHU                74348211114    RIEDER,HEINZ  74348211       2011-03-23        2011-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682608  (null)             415008623  2008-10-09  SZMZR#97  1           0           0               1           0           5.1/BDO               74348211114    RIEDER,HEINZ  74348211       2008-10-10        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682610  (null)             415008623  2008-10-08  SZMZR#92  1           0           0               1           0           VL 3.1/LUC 8.10.      74348211114    RIEDER,HEINZ  74348211       2008-10-09        2008-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
515682612  (null)             415008623  2011-03-22  SZMZR#97  1           1           0               1           0           IK MHU                74348211114    RIEDER,HEINZ  74348211       2011-03-23        2011-12-01   RH59C               (null)          7561111667528  RIEDER,HEINZ  (null)                  (null)                   2011-09-25 14:31:38  
936376437  (null)             415008623  2013-03-20  SZMZR#71  1           3           0               1           0           VL 2.3 VOG 20.03.13   74348211114    RIEDER,HEINZ  74348211       2013-03-21        2012-12-01   ZAS                 WOHNSITZ#1      7561111667528  RIEDER,HEINZ  (null)                  (null)                   2013-03-22 20:51:32  
936378454  (null)             415008623  2013-03-20  SZMZR#71  1           0           0               1           0           VL 2.3 VOG 20.03.13   74348211114    RIEDER,HEINZ  74348211       2013-03-21        2012-12-01   ZAS                 WOHNSITZ#1      7561111667528  RIEDER,HEINZ  (null)                  (null)                   2013-03-22 20:54:02  
936379138  (null)             415008623  2013-03-20  SZMZR#71  1           1           0               1           0           VL 2.3 VOG 20.03.13   74348211114    RIEDER,HEINZ  74348211       2013-03-21        2012-12-01   ZAS                 WOHNSITZ#1      7561111667528  RIEDER,HEINZ  (null)                  (null)                   2013-03-22 20:54:35  
*/
select * from vista.tikzikexecution where vnr='74348211114';
/*
TIKZEXCID  TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME       BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
---------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  ------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
547173370  515682592  (null)           (null)           528216478         2011-03-24        0            0                    1      0      74348211114    RIEDER,HEINZ  0                        0                      0               2011-03-24     RH59C       1          2011-03-24    (null)                        2011-09-25 19:34:18  
547173394  515682608  (null)           (null)           528216476         2008-10-14        0            0                    1      0      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-14     RH59C       1          2008-10-14    (null)                        2011-09-25 19:34:18  
547173397  515682610  (null)           (null)           528216480         2008-10-10        0            0                    1      0      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-10     RH59C       1          2008-10-10    (null)                        2011-09-25 19:34:18  
936372138  936378454  (null)           (null)           936372140         2013-03-22        0            0                    1      0      74348211114    RIEDER,HEINZ  0                        0                      0               2013-03-22     ZHIK0A01    1          2013-03-21    0                             2013-03-22 21:47:10  
547173373  515682594  (null)           (null)           529880634         2001-01-11        0            0                    1      1      74348211114    RIEDER,HEINZ  0                        0                      0               2001-01-11     RH21C       1          2001-01-11    (null)                        2011-09-25 19:34:18  
547173376  515682596  (null)           (null)           528216480         2008-10-10        0            0                    1      1      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-10     RH59C       1          2008-10-10    (null)                        2011-09-25 19:34:18  
547173379  515682598  (null)           (null)           528216476         2008-10-14        0            0                    1      1      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-14     RH59C       1          2008-10-14    (null)                        2011-09-25 19:34:18  
547173400  515682612  (null)           (null)           528216478         2011-03-24        0            0                    1      1      74348211114    RIEDER,HEINZ  0                        0                      0               2011-03-24     RH59C       1          2011-03-24    (null)                        2011-09-25 19:34:18  
936372136  936379138  (null)           (null)           936372140         2013-03-22        0            0                    1      1      74348211114    RIEDER,HEINZ  0                        0                      0               2013-03-22     ZHIK0A01    1          2013-03-21    0                             2013-03-22 21:47:06  
547173382  515682600  (null)           (null)           529880634         2001-01-10        0            0                    1      3      74348211114    RIEDER,HEINZ  0                        0                      0               2001-01-10     RH59C       1          2001-01-10    (null)                        2011-09-25 19:34:18  
547173385  515682602  (null)           (null)           528216476         2008-10-14        0            0                    1      3      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-14     RH59C       1          2008-10-14    (null)                        2011-09-25 19:34:18  
547173388  515682604  (null)           (null)           528216480         2008-10-10        0            0                    1      3      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-10     RH59C       1          2008-10-10    (null)                        2011-09-25 19:34:18  
547173391  515682606  (null)           (null)           528216478         2011-03-24        0            0                    1      3      74348211114    RIEDER,HEINZ  0                        0                      0               2011-03-24     RH59C       1          2011-03-24    (null)                        2011-09-25 19:34:18  
936372137  936376437  (null)           (null)           936372140         2013-03-22        0            0                    1      3      74348211114    RIEDER,HEINZ  0                        0                      0               2013-03-22     ZHIK0A01    1          2013-03-21    0                             2013-03-22 21:47:06  
538208206  (null)     (null)           (null)           528216476         2008-10-13        0            0                    33     0      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-13     RH21C       1          2008-10-13    (null)                        2011-09-25 18:08:08  
538208208  (null)     (null)           (null)           528216480         2008-10-13        0            0                    33     0      74348211114    RIEDER,HEINZ  0                        0                      0               2008-10-13     RH21C       1          2008-10-13    (null)                        2011-09-25 18:08:08  
538208210  (null)     (null)           (null)           529880634         2001-01-10        0            0                    33     0      74348211114    RIEDER,HEINZ  0                        0                      0               2001-01-10     RH21C       1          2001-01-10    (null)                        2011-09-25 18:08:08  
538208212  (null)     (null)           (null)           528216478         2011-03-24        0            0                    33     0      74348211114    RIEDER,HEINZ  0                        0                      0               2011-03-24     RH21C       1          2011-03-24    (null)                        2011-09-25 18:08:08  
936372135  (null)     (null)           (null)           936372140         2013-03-22        0            0                    33     0      74348211114    RIEDER,HEINZ  0                        0                      0               2013-03-22     ZHIK0A01    1          2013-03-21    0                             2013-03-25 21:17:04  
*/
select * from vista.tikrequestheader where pendvnr='74348211114'; -- empty
select * from vista.tikinsurancerequest where customer=379886082; -- empty
select * from vista.tikcollection where tikcollid in (select tikcollid_actual from vista.tikzikexecution where vnr='74348211114');
/*
TIKCOLLID  TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE             CSZ       VNR            VNRNAME       VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE    ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  LASTUPDATED          
---------  ---------  ----------  ----------  ----------  -------------------  --------  -------------  ------------  -------------  -----------  -------------  ------------  ----------------  ---------  -------------------  ---------  -------------------  
528216476  406543882  2008-10-09  1           0           5.1/BDO              SZMZR#97  7561111667528  RIEDER,HEINZ                 (null)       7561111667528  2008-10-10    2008-10-14        (null)     (null)               (null)     2011-09-25 16:39:09  
528216478  406543882  2011-03-22  1           0           IK MHU               SZMZR#97  7561111667528  RIEDER,HEINZ                 (null)       7561111667528  2011-03-23    2011-03-25        (null)     (null)               (null)     2011-09-25 16:39:09  
528216480  406543882  2008-10-08  1           0           VL 3.1/LUC 8.10.     SZMZR#92  7561111667528  RIEDER,HEINZ                 (null)       7561111667528  2008-10-09    2008-10-14        (null)     (null)               (null)     2011-09-25 16:39:09  
529880634  415008623  2001-01-08  1           0           F/MN                 SZMZR#97  74348211114    RIEDER,HEINZ  74348211       2001-01-01   74348211114    2001-01-09    2001-01-12        (null)     (null)               (null)     2011-09-25 16:52:44  
936372140  406543882  2013-03-20  1           0           VL 2.3 VOG 20.03.13  SZMZR#71  7561111667528  RIEDER,HEINZ  (null)         2012-12-01   7561111667528  2013-03-21    (null)            (null)     VDR6515020004460263  (null)     2013-03-22 20:47:04  
*/

-- CASE 3 -----------------------------------------------------
/*
SZ85 also not working
ZIK data (Reason, AK, BO) are incomplete  Message Code: IKACC02003 
*/
select * from vista.aurupiregister where new_nnss='7560000265586';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
591779822         7560000265586    7560000265586  0         1            WULLSCHLEGER,ERICH  1         23051955  100            950000    (null)     1              (null)             (null)             (null)         2018-07-04 15:04:38  
591779823         7560000265586    7560000265586  0         0            WULLSCHLEGER,ERICH  1         23051955  100            950000    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
591779824         7560000265586    7560000265586  0         0            WULLSCHLEGER,ERICH  1         23051955  100            970000    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
627336378         96655254118      7560000265586  0         0            WULLSCHLEGER,ERICH  1         23051955  100            (null)    (null)     (null)         (null)             (null)             (null)         2018-07-04 15:04:38  
*/
select * from vista.tikheader where vnr='7560000265586' or tikownrid=401196166;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
406188489  401196166  7560000265586  WULLSCHLEGER,ERICH  1955       5           23        SEXCODEZAS#1  BSVLAND#100  96655254118    F                2014-10-09 20:25:55  
417350912  401196166  96655254118    WULLSCHLEGER,ERICH  1955       5           23        SEXCODEZAS#1  BSVLAND#100                 F                2011-09-24 20:09:17  
*/
select * from vista.tikowner where tikownrid=401196166;
/*
TIKOWNRID  KPVROLEID  LASTUPDATED          
---------  ---------  -------------------  
401196166  377848157  2011-09-24 17:50:33  
*/
select * from vista.tikaccount where tikheadid=406188489;
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE              CSTATE      CZIKREASON  ZIKAK  ZIKBO  ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  --------------------  ----------  ----------  -----  -----  --------------  -------------------  
417718821  406188489  ACCTYPE#IK    2008          SZMZR#68         RHA0C150000000371914  IKSTATUS#O  SZMZR#85    1      3      1999-12-01      2011-09-24 20:14:20  
*/
select * from vista.tikzikrequest where kpvroleid=377848157 or vnrla='7560000265586'; -- empty
select * from vista.tikzikorder where tikheadid=406188489 or vnr='7560000265586';
/*
TIKZIORID   TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE              VNR            VNRNAME             VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME           CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------------------  -------------  ------------------  -------------  ----------------  -----------  ------------------  --------------  -------------  ------------------  ----------------------  -----------------------  -------------------  
518141128   (null)             406188489  2008-09-04  SZMZR#85  1           0           0               1           3           Bei IK-Eroffnung gen  7560000265586  WULLSCHLEGER,ERICH  (null)         2008-09-03        1999-12-01   RH16C               (null)          7560000265586                      (null)                  (null)                   2015-05-20 13:03:11  
518141130   (null)             406188489  2009-03-26  SZMZR#98  1           0           0               1           0           IV 1.3/BUC            7560000265586  WULLSCHLEGER,ERICH  (null)         2009-03-27        2009-12-01   RH59C               (null)          7560000265586  WULLSCHLEGER,ERICH  (null)                  (null)                   2011-09-25 14:56:31  
1426564916  (null)             406188489  2014-10-07  SZMZR#98  1           0           0               1           0           IV1.3MAC              7560000265586  WULLSCHLEGER,ERICH  (null)         2014-10-08        2014-12-01   ZAS                 (null)          (null)         (null)              (null)                  (null)                   2014-10-09 20:37:49  
*/
select * from vista.tikzikexecution where vnr='7560000265586' or tikziorid in (518141128, 518141130, 1426564916);
/*
TIKZEXCID   TIKZIORID   TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME             BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
----------  ----------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  ------------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
542110535   518141130   (null)           (null)           528204586         2009-03-30        0            0                    1      0      7560000265586  WULLSCHLEGER,ERICH  0                        0                      0               2009-03-30     RH59C       1          2009-03-30    (null)                        2011-09-25 18:45:54  
550348813   518141128   (null)           (null)           (null)            2008-09-04        0            0                    1      0      7560000265586  WULLSCHLEGER,ERICH  0                        0                      0               2008-09-04     RH16C       1          2008-09-03    (null)                        2011-09-25 20:06:27  
1426508010  1426564916  (null)           (null)           1426508012        2014-10-09        0            0                    1      0      7560000265586  WULLSCHLEGER,ERICH  0                        0                      0               2014-10-09     ZHIK0A01    1          2014-10-08    0                             2014-10-09 20:51:23  
1426508011  (null)      (null)           (null)           1426508012        2014-10-09        0            0                    65     0      7560000265586  WULLSCHLEGER,ERICH  0                        0                      0               2014-10-09     ZHIK0A01    1          2014-10-08    0                             2014-10-10 20:47:04  
*/
select * from vista.tikrequestheader where pendvnr='7560000265586'; -- empty
select * from vista.tikinsurancerequest where customer=377848157; -- empty
select * from vista.tikcollection where tikcollid in (528204586, 1426508012);
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE    CSZ       VNR            VNRNAME             VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE    ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  LASTUPDATED          
----------  ---------  ----------  ----------  ----------  ----------  --------  -------------  ------------------  -------------  -----------  -------------  ------------  ----------------  ---------  -------------------  ---------  -------------------  
528204586   406188489  2009-03-26  1           0           IV 1.3/BUC  SZMZR#98  7560000265586  WULLSCHLEGER,ERICH                 (null)       7560000265586  2009-03-27    2009-03-30        (null)     (null)               (null)     2011-09-25 16:39:00  
1426508012  406188489  2014-10-07  1           0           IV1.3MAC    SZMZR#98  7560000265586  WULLSCHLEGER,ERICH  (null)         (null)       (null)         2014-10-08    (null)            (null)     VDR8011230014888239  (null)     2014-10-09 20:29:34  
*/

select * from vista.tikbooking where tikacctid=417718821;
/*
TIKBOOKID   TIKBOOKID_STORNO  TIKACCTID  TIKBOPEID   TIKINRETID  TIKBOOKID_REBOOKED  TIKCTCAID  BNOCHECKCODE  BOOKINGDATE  BILLNBR      INCOME    CCONTRIBUTIONTYPE  CCARETAKINGFACTOR  NBRINSURED  PENDVNR  PENDNAME  PENDFIRSTNAME  CEMPLOYEECODE  BASYLUMCODE  BWRITEOFFCODE  BPROVCODE  BPAPERIK  NBRAK  NBRBO  BSUPPRESSEDBOOKING  SPOUSEVNR  BMANSPLITTBOOKFLTIMES  BOOKEDBY  CLASTACTION   IKLASTACTIONDATE  IKLASTACTIONBY  BPENSIONZIK  CSTORNOCODE  BIEDV2000ID       CSPECIALCODE  CCODEADS  CSECTOR  CTOWNSHIP  BWDECREEOID  BWLISTOID  BWENTRYOID  PROCESSID  LASTUPDATED          
----------  ----------------  ---------  ----------  ----------  ------------------  ---------  ------------  -----------  -----------  --------  -----------------  -----------------  ----------  -------  --------  -------------  -------------  -----------  -------------  ---------  --------  -----  -----  ------------------  ---------  ---------------------  --------  ------------  ----------------  --------------  -----------  -----------  ----------------  ------------  --------  -------  ---------  -----------  ---------  ----------  ---------  -------------------  
1140690328  (null)            417718821  1140690329  1151292202  (null)              (null)     0             2013-12-03   S69675       11000.00  SZBEITRART#4       (null)             0           (null)   (null)    (null)         YESNO#N        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2013-12-03        ZHIK0A01        0            SZSTORNO#0   1000000002380364  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2013-12-03 00:11:18  
1329445856  (null)            417718821  1329445857  1334759444  (null)              (null)     0             2014-06-02   S69675       11000.00  SZBEITRART#4       (null)             0           (null)   (null)    (null)         YESNO#N        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2014-06-02        ZHIK0A01        0            SZSTORNO#0   1000000003306985  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2014-06-02 23:47:50  
1329445858  (null)            417718821  1329445859  1334759444  (null)              (null)     0             2014-06-02   S69675       11000.00  SZBEITRART#4       (null)             0           (null)   (null)    (null)         YESNO#N        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2014-06-02        ZHIK0A01        0            SZSTORNO#0   1000000003306986  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2014-06-02 23:47:51  
1442764883  (null)            417718821  1442764884  1464855474  (null)              (null)     0             2014-11-03   S69675       11000.00  SZBEITRART#4       (null)             0           (null)   (null)    (null)         YESNO#N        0            0              0          0         1      0      0                   (null)     0                      ZHIK0A01  IKBUCHHIST#n  2014-11-03        ZHIK0A01        0            SZSTORNO#0   1000000003552877  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2014-11-03 23:46:51  
*/
select * from vista.tikperiod where tikbopeid in (select distinct tikbopeid from vista.tikbooking where tikacctid=417718821);
/*
TIKBOPEID   ENDDATE     BEGINDATE   NBRMONTHS  REFYEAR  CSPECIALITY  ENDMONTH  BEGINMONTH  TYPE  LASTUPDATED          
----------  ----------  ----------  ---------  -------  -----------  --------  ----------  ----  -------------------  
1140690329  2011-12-31  2011-01-01  (null)     (null)   (null)       (null)    (null)      1     2013-12-03 00:11:18  
1329445857  2009-12-31  2009-01-01  (null)     (null)   (null)       (null)    (null)      1     2014-06-02 23:47:50  
1329445859  2010-12-31  2010-01-01  (null)     (null)   (null)       (null)    (null)      1     2014-06-02 23:47:51  
1442764884  2012-12-31  2012-01-01  (null)     (null)   (null)       (null)    (null)      1     2014-11-03 23:46:51  
*/

--
select * from vista.aurupiregister upi where upi.old_ahv_or_nnss in (

select head.vnr from vista.tikheader head inner join vista.tikaccount acc 
 on head.TIKHEADID=acc.TIKHEADID 
inner join  vista.tikbooking book
on acc.TIKACCTID=book.TIKACCTID
 inner join vista.TIKPERIOD bkp 
on bkp.TIKBOPEID= book.TIKBOPEID 
and book.BILLNBR='G41075'
and year(BEGINDATE)> 2013

);


select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE='1112610060001136023'
and var.parmname like 'IG_IK%'
with ur;

select * from vista.tpvdynamicparams;
update vista.tpvdynamicparams set lastupdated=current timestamp where paramname='PVJREPLI_START';


-- Defect 8323 - Internal Splitting - NullPointer
-- SIT417
select * from vista.tikheader where vnr='7562180706477' or tikownrid=76984539;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                        BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  --------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
80100403   76984539   7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  1959       7           20        SEXCODEZAS#2  BSVLAND#100  68759720117    F                2011-05-16 23:19:34  
80999057   76984539   68759720117    NUSSBAUMER,BRIGITTE         1959       7           20        SEXCODEZAS#2  BSVLAND#100  7562180706477  F                2011-05-16 22:53:58  
*/
select * from vista.tikowner where tikownrid=76984539;
/*
TIKOWNRID  KPVROLEID  LASTUPDATED          
---------  ---------  -------------------  
76984539   71987947   2010-09-22 12:25:45  
*/
select * from vista.tikaccount where tikheadid=80100403;
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE             CSTATE      CZIKREASON  ZIKAK  ZIKBO  ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  -------------------  ----------  ----------  -----  -----  --------------  -------------------  
83020428   80100403   ACCTYPE#IK    2011          SZMZR#65         AUT. WIEDEREROEFFN.  IKSTATUS#W  SZMZR#85    12     0      2006-12-01      2011-05-16 23:19:34  
*/
select * from vista.tiksplittingorder where vnr='7562180706477' or tikheadid=80100403; -- empty
select * from vista.tikzikorder where vnr='7562180706477' or tikheadid=80100403; 
/*
TIKZIORID  TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE            VNR            VNRNAME                     VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME                   CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
---------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  ------------------  -------------  --------------------------  -------------  ----------------  -----------  ------------------  --------------  -------------  --------------------------  ----------------------  -----------------------  -------------------  
114037502  (null)             80100403   2009-12-28  SZMZR#98  17          0           0               17          0           IV/KT3/SG           7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)         2009-12-29        2009-12-01   RH59C               (null)          7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)                  (null)                   2010-09-22 21:34:26  
115304302  (null)             80100403   2010-03-11  SZMZR#98  17          0           0               12          0           012MM               7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)         2010-03-11        2010-12-01   RH59C               (null)          7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)                  (null)                   2010-09-22 22:02:50  
281329864  (null)             80100403   2011-05-13  SZMZR#85  17          0           0               12          0           012BH               7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)         2011-05-13        2006-12-01   ZAS                 (null)          7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)                  (null)                   2011-05-13 23:04:12  
387954285  (null)             80100403   2012-03-09  SZMZR#98  17          0           0               2           0           02/0903/124630/RSD  7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)         2012-03-12        2012-12-01   ZAS                 (null)          (null)         (null)                      (null)                  (null)                   2012-03-12 21:39:58  
618268984  (null)             80100403   2014-03-07  SZMZR#98  17          0           0               2           0           11/0703/423485/IVB  7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  (null)         2014-03-10        2014-12-01   ZAS                 (null)          (null)         (null)                      (null)                  (null)                   2014-03-11 20:31:53  
*/
select * from vista.tikzikexecution where tikziorid in (select tikziorid from vista.tikzikorder where vnr='7562180706477' or tikheadid=80100403) or vnr='7562180706477';
/*
TIKZEXCID   TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME                     BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
----------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  --------------------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
117550831   (null)     (null)           (null)           116542828         2009-12-30        0            0                    105    0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2009-12-30     RH21C       1          2009-12-30    (null)                        2010-09-22 22:52:16  
117609676   (null)     (null)           (null)           116542828         2009-12-30        0            0                    2      0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2009-12-30     RH21C       1          2009-12-30    (null)                        2010-09-22 22:53:21  
120666218   114037502  (null)           (null)           116542828         2009-12-30        0            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2009-12-30     RH59C       1          2009-12-30    (null)                        2010-09-22 23:52:49  
122925983   115304302  (null)           (null)           (null)            2010-03-12        0            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2010-03-12     RH59C       1          2010-03-11    (null)                        2010-09-23 00:37:01  
281329865   281329864  (null)           (null)           (null)            2011-05-14        0            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2011-05-14     SGIK0A01    1          2011-05-13    0                             2011-05-14 00:28:27  
387954286   387954285  (null)           (null)           (null)            2012-03-12        0            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2012-03-12     SGIK0A01    1          2012-03-12    0                             2012-03-12 22:29:45  
618268987   618268984  (null)           (null)           (null)            2014-03-11        0            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2014-03-11     SGIK0A01    1          2014-03-10    0                             2014-03-11 20:58:48  
1533155283  (null)     (null)           1533154775       (null)            2018-07-12        0            0                    17     0      7562180706477  (null)                      1                        0                      0               2018-07-12     SGIK0A01    1          2018-07-12    (null)                        2018-07-12 14:59:16  
1533155289  281329864  (null)           (null)           (null)            2018-07-12        1            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2018-07-12     SGIK0A01    1          2018-07-12    (null)                        2018-07-12 21:38:49  
1533265244  281329864  (null)           (null)           (null)            2018-07-12        1            0                    17     0      7562180706477  NUSSBAUMER,BRIGITTE HEDWIG  0                        0                      0               2018-07-12     SGsit522    (null)     2018-07-12    (null)                        2018-07-12 14:59:16  
*/
select * from vista.tiksplittingexecution; -- empty for this case
select * from vista.tikcollection where vnr='7562180706477' or tikheadid=80100403;
/*
TIKCOLLID  TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE   CSZ       VNR            VNRNAME                     VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE    ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF  KPVADRSID  LASTUPDATED          
---------  ---------  ----------  ----------  ----------  ---------  --------  -------------  --------------------------  -------------  -----------  -------------  ------------  ----------------  ---------  -----------  ---------  -------------------  
116542828  80100403   2009-12-28  17          0           IV/KT3/SG  SZMZR#98  7562180706477  NUSSBAUMER,BRIGITTE HEDWIG                 (null)       7562180706477  2009-12-29    2010-01-05        (null)     (null)       (null)     2010-09-22 22:31:15  
*/
select * from vista.tikzikrequest where vnrla='7562180706477' or kpvroleid=71987947; -- empty
select * from vista.tikinsurancerequest where customer=71987947; -- empty
select * from vista.tikvaikrequest where kpvroleid=71987947; -- empty


-- Defect 8341_IK_CBUSINESSSECTOR NULL for bookings w.o. billno
select * from vista.tikemployerarchive where billnbr='348458';
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                        ADR2             ADR3                  ADR4            KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -------  ----------  -----------  --------------------------  ---------------  --------------------  --------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
597073704  348458   (null)      BRANCHE#85   Polit. Gemeinde Gaiserwald  Schulverwaltung  Sonnenbergstrasse 15  9030 Abtwil SG  15368095        CHE306550370  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#N  72814                 63469             28731                 63469                     1948-01-01  9999-12-31  abc6f345-f077-491e-80c9-40bb6d4b88f3  10850600    10850600        15368095            SONDERFALL#03  956249    MEMBERTYP#AK  2018-03-01 18:10:36  
*/
select * from vista.tikemployerarchive where billnbr='0/62';

select * from vista.tzaxmlmzrrecord where date(lastupdated) >= '2018-07-10' and recorddata like '%Erwerbszweig>85%'; -- zzaxmlmzrrecordid=1537741197 --> messagetype = IKMeldung
select * from vista.tikbookingdelivered where tikbopeid in (1537733248, 1537753312) order by lastupdated desc;
/*
TIKBODVID   TIKZEXCID   TIKBOPEID   TIKEXECPROVID  BILLZIP  BILLDESCR  INCOME     BILLNBR        CCONTRIBUTIONTYPE  CBUSINESSSECTOR  CCARETAKINGFACTOR  CSPECIALCASE  CAMORTISATIONCODE  CSTORNOCODE  LASTUPDATED          
----------  ----------  ----------  -------------  -------  ---------  ---------  -------------  -----------------  ---------------  -----------------  ------------  -----------------  -----------  -------------------  
1537753313  1537752690  1537753312  (null)         (null)   (null)     44800.00   0/62           SZBEITRART#1       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-07-16 16:29:44  
1537733249  1537732506  1537733248  (null)         (null)   (null)     120112.00  0/62           SZBEITRART#1       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-07-16 13:24:26  
*/
select * from vista.tzaxmlmzrrecord where date(lastupdated) >= '2018-07-10' and recorddata like '%7565550454428%' and recorddata like '%0/62%'; -- empty
select * from vista.tikperiod where tikbopeid in (1537733248, 1537753312);
/*
TIKBOPEID   ENDDATE  BEGINDATE  NBRMONTHS  REFYEAR  CSPECIALITY  ENDMONTH  BEGINMONTH  TYPE  LASTUPDATED          
----------  -------  ---------  ---------  -------  -----------  --------  ----------  ----  -------------------  
1537733248  (null)   (null)     (null)     2008     (null)       12        1           4     2018-07-16 13:24:26  
1537753312  (null)   (null)     (null)     2009     (null)       12        1           4     2018-07-16 16:29:44  
*/
select * from vista.tikbookingdata where tikbopeid in (1537733248, 1537753312); -- empty
select * from vista.tikbooking where tikbopeid in (1537733248, 1537753312); -- empty
select * from vista.tikzikexecution where tikzexcid in (1537752690, 1537732506);
/*
TIKZEXCID   TIKZIORID   TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME        BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
----------  ----------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  -------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
1537752690  1537752862  (null)           (null)           1537752695        2018-07-16        0            0                    17     0      7565550454428  SIEBER,YVONNE  0                        0                      0               2018-07-16     SGIK0A01    1          2018-07-17    0                             2018-07-16 16:29:44  
1537732506  1537732677  (null)           (null)           1537732511        2018-07-16        0            0                    17     0      7565550454428  SIEBER,YVONNE  0                        0                      0               2018-07-16     SGIK0A01    1          2018-07-16    0                             2018-07-16 13:24:26  
*/
select * from vista.tikzikorder where tikziorid in (1537752862, 1537732677);
/*
TIKZIORID   TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE  VNR            VNRNAME        VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME      CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------  -------------  -------------  -------------  ----------------  -----------  ------------------  --------------  -------------  -------------  ----------------------  -----------------------  -------------------  
1537752862  (null)             81299601   2018-07-17  SZMZR#98  17          0           0               17          0           GRIMM     7565550454428  SIEBER,YVONNE  (null)         2018-07-17        2018-12-01   ZAS                 (null)          7565550454428  SIEBER,YVONNE  (null)                  (null)                   2018-07-16 16:29:00  
1537732677  (null)             81299601   2018-07-16  SZMZR#98  17          0           0               17          0           GRIMM     7565550454428  SIEBER,YVONNE  (null)         2018-07-16        2018-12-01   ZAS                 (null)          7565550454428  SIEBER,YVONNE  (null)                  (null)                   2018-07-16 13:23:39  
*/
select * from vista.tikheader where tikheadid in (81299601);
/*
TIKHEADID  TIKOWNRID  VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
81299601   76520205   7565550454428  SIEBER,YVONNE  1958       1           1         SEXCODEZAS#2  BSVLAND#100  78658501118    F                2017-03-10 20:28:24  
*/

-- Guardian Relation
select * from vista.tpvrolerel where crelationtype='RoleRelati#GV'; select * from vista.tpvrole where kpvroleid=35021448; -- source = STA, target = VET
select * from vista.tpvtelecom;


select birthdate from vista.tpvpartner;

select * from vista.tpvpartner where clegaltype like '%#AK' order by compfundnr; -- compfundnr / compfundbranchnr
select * from vista.tpvpartner where clegaltype like '%#AHVZ' order by ahvbranchnr; -- ahvbranchnr


-- 182053 - TG: Incident MQ-Schnittstelle: LZ.PV-I001
/*
 <head>
        <senderId>BZ-PV</senderId>
        <initiatedSenderId>BZ-PV</initiatedSenderId>
        <messageID>4944cda5-6f1f-4e73-b45e-9fb303ead0de</messageID>
        <businessProcessID>fc576786-8741-4638-b76b-c4619cc98df6</businessProcessID>
        <message>
            <type>igs-0043</type>
            <version>2.0</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.34.4</sendingProductVersion>
        </sendingApplication>
        <messageDate>2018-07-31T14:52:38.000+02:00</messageDate>
        <initialMessageDate>2018-07-31T14:52:38.000+02:00</initialMessageDate>
        <eventDate>2018-07-31T14:52:38.000+02:00</eventDate>
        <tenant>TG</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:nnss>7565652229733</ns2:nnss>
        <ns2:bzPartnerKey>58397317-708c-40da-98f2-6b42cd1f1401</ns2:bzPartnerKey>
        <ns2:roleType>FAK</ns2:roleType>
        <ns2:historizedRoleData>
            <ns2:active>0</ns2:active>
            <ns2:validFrom>1989-05-01</ns2:validFrom>
            <ns2:validTill>2018-07-30</ns2:validTill>
        </ns2:historizedRoleData>
    </ns2:body>
</ns2:IGS-CreateUpdateRoleRequest> 
*/
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated)='2018-07-31';
select * from vista.tsfmqinbound where jmsmessageid='4944cda5-6f1f-4e73-b45e-9fb303ead0de' or jmscorrelationid='4944cda5-6f1f-4e73-b45e-9fb303ead0de'; -- empty
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and lastupdated between '2018-07-31 14:53:00' and '2018-07-31 14:54:00'; -- tsfmqinboundid = 794580400
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                       JMSREPLYTO  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------  ----------  ------------------------------------  --------  ------  --------  ----------------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
794580400       0       (null)  JMSTextMessage   LZ.PV-I001  2                0              4            ID:414d5120414258315447502020202020d12d555b252f914c  1533041625500  114a4f77-46d8-4190-9a78-a33ea6c99544  queue:///BZBW.LZPV.I001.ROLE.UPDATE  (null)      ede4b1cb-c3d4-473c-b6fd-0b92bf2556fd  TG        (null)  tgks      de                <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-CreateUpdateRoleRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0043/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2">
    <head>
        <senderId>BZ-PV</senderId>
        <initiatedSenderId>BZ-PV</initiatedSenderId>
        <messageID>401f166c-d371-4b3c-8fc7-6571a2b98d4f</messageID>
        <businessProcessID>ede4b1cb-c3d4-473c-b6fd-0b92bf2556fd</businessProcessID>
        <message>
            <type>igs-0043</type>
            <version>2.0</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.34.4</sendingProductVersion>
        </sendingApplication>
        <messageDate>2018-07-31T14:53:45.000+02:00</messageDate>
        <initialMessageDate>2018-07-31T14:53:45.000+02:00</initialMessageDate>
        <eventDate>2018-07-31T14:53:45.000+02:00</eventDate>
        <tenant>TG</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:nnss>7565652229733</ns2:nnss>
        <ns2:bzPartnerKey>58397317-708c-40da-98f2-6b42cd1f1401</ns2:bzPartnerKey>
        <ns2:roleType>FAK</ns2:roleType>
        <ns2:historizedRoleData>
            <ns2:active>1</ns2:active>
            <ns2:validFrom>1989-05-01</ns2:validFrom>
            <ns2:validTill>9999-12-31</ns2:validTill>
        </ns2:historizedRoleData>
    </ns2:body>
</ns2:IGS-CreateUpdateRoleRequest>   2018-07-31 14:53:45 
*/
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and lastupdated between '2018-07-31 14:53:00' and '2018-07-31 14:54:00' and tsfmqinboundid = 794580400;
select * from vista.tpvpartner where personid='7565652229733'; -- 98608156
select * from vista.tpvrole where kpvpartid=98608156;
select * from vista.jpvrole where kpvpartid=98608156 and croletype='Rolle#FAK';
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                 OPERATION  
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ----------------------  ---------  
766035572  766035571  98608156   Rolle#FAK  (null)     (null)       N       2013-07-01  9999-12-31  2018-06-01 09:03:24  2018-06-01 09:03:24  DB2ADM       CLP importBZRollen.sql  I          
766035572  766035571  98608156   Rolle#FAK  (null)     (null)       N       2013-07-01  9999-12-31  2018-06-01 09:03:24  2018-07-31 14:53:45  tgks         PV:LZ.PV-I001-V2        D          
794580413  794580415  98608156   Rolle#FAK  (null)     (null)       Y       1989-05-01  9999-12-31  2018-07-31 14:53:45  2018-07-31 14:53:45  tgks         PV:LZ.PV-I001-V2        I          
794580413  794580415  98608156   Rolle#FAK  (null)     (null)       Y       1989-05-01  9999-12-31  2018-07-31 14:53:45  2018-08-06 16:58:00  tgks         PV:LZ.PV-I001-V2        D          
797250787  797250788  98608156   Rolle#FAK  (null)     (null)       N       1989-05-01  9999-12-31  2018-08-06 16:58:00  2018-08-06 16:58:00  tgks         PV:LZ.PV-I001-V2        I  
*/

-- 181978 - SG - Incident MQ-Schnittstelle: LZ.PV-I001
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and lastupdated between '2018-07-31 07:09:00' and '2018-07-31 07:10:30'; -- tsfmqinboundid = 1577370833
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                       JMSREPLYTO  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------  ----------  ------------------------------------  --------  ------  --------  ----------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
1577370833      0       (null)  JMSTextMessage   LZ.PV-I001  2                0              4            ID:414d5120414258315347502020202020d12d555b25cf0880  1533013800455  59e97090-1a9f-4c2c-8a4f-df7f0f9ec911  queue:///BZBW.LZPV.I001.ROLE.UPDATE  (null)      8feefc0f-1fbc-4d81-b7b8-d4aabaddbdf4  SG        (null)  SGCS0A01  de                <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-CreateUpdateRoleRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0043/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2">
    <head>
        <senderId>BZ-PV</senderId>
        <initiatedSenderId>BZ-PV</initiatedSenderId>
        <messageID>b43b433c-f712-4560-9294-21e58e2f6ce0</messageID>
        <businessProcessID>8feefc0f-1fbc-4d81-b7b8-d4aabaddbdf4</businessProcessID>
        <message>
            <type>igs-0043</type>
            <version>2.0</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.34.4</sendingProductVersion>
        </sendingApplication>
        <messageDate>2018-07-31T07:10:00.000+02:00</messageDate>
        <initialMessageDate>2018-07-31T07:10:00.000+02:00</initialMessageDate>
        <eventDate>2018-07-31T07:10:00.000+02:00</eventDate>
        <tenant>SG</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:nnss>7566329341154</ns2:nnss>
        <ns2:bzPartnerKey>574e427f-64d2-4ef5-8c6d-d0cacf152b16</ns2:bzPartnerKey>
        <ns2:roleType>AG</ns2:roleType>
        <ns2:historizedRoleData>
            <ns2:active>0</ns2:active>
            <ns2:validFrom>1900-01-01</ns2:validFrom>
            <ns2:validTill>2018-07-30</ns2:validTill>
        </ns2:historizedRoleData>
    </ns2:body>
</ns2:IGS-CreateUpdateRoleRequest>  2018-07-31 07:10:00  
*/
select * from vista.tpvpartner where personid='7566329341154'; -- 9324538
select * from vista.jpvrole where kpvpartid=9324538 and croletype='Rolle#AG';
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                      OPERATION  
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ---------------------------  ---------  
1441699880  1441699879  9324538    Rolle#AG   (null)     (null)       (null)  2003-01-01  9999-12-31  2018-03-02 13:23:37  2018-03-02 13:23:37  PEKREMER     CLP importBZRollen_V.04.sql  I          
1441699880  1441699879  9324538    Rolle#AG   (null)     (null)       (null)  2003-01-01  9999-12-31  2018-03-02 13:23:37  2018-08-06 16:56:37  SGCS0A01     PV:LZ.PV-I001-V2             D          
1583489879  1583489881  9324538    Rolle#AG   (null)     (null)       N       1900-01-01  9999-12-31  2018-08-06 16:56:37  2018-08-06 16:56:37  SGCS0A01     PV:LZ.PV-I001-V2             I          
*/


-- AndrÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¡ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬ÃƒÂ¢Ã¢â‚¬Å¾Ã‚Â¢ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¢ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬Ãƒâ€¦Ã‚Â¡ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â©, 08.08.2018 - Zuweisung POLG gemss Botenfile
select * from vista.abdpostfilestreet where bfsnr in (5712, 5717) and street like 'Chemin des Bo%' and streetnr <= 3;
/*
TBDPOSTFILESTREETID  STREET                 ZIP4  ZIPADDON  ZIP6    SHORTCITY  COUNTRY  ADDRSCANTON  STREETNR  STREETNRADDON  POLGNAME  POLGCANTON  BFSNR  LASTUPDATED          
-------------------  ---------------------  ----  --------  ------  ---------  -------  -----------  --------  -------------  --------  ----------  -----  -------------------  
1547726              Chemin des Bocages     1296  00        129600  Coppet     CH       VD           2         (null)         Coppet    VD          5712   2018-06-06 12:58:47  
1547737              Chemin des Bochattets  1296  00        129600  Coppet     CH       VD           1         (null)         Coppet    VD          5712   2018-06-06 12:58:47  
1547746              Chemin des Bochattets  1296  00        129600  Coppet     CH       VD           2         (null)         Coppet    VD          5712   2018-06-06 12:58:47  
1547756              Chemin des Bochattets  1296  00        129600  Coppet     CH       VD           3         (null)         Coppet    VD          5712   2018-06-06 12:58:47  
1550647              Chemin des Bosquets    1297  00        129700  Founex     CH       VD           1         (null)         Founex    VD          5717   2018-06-06 12:58:47  
1550648              Chemin des Bosquets    1297  00        129700  Founex     CH       VD           2         (null)         Founex    VD          5717   2018-06-06 12:58:47  
1550649              Chemin des Bosquets    1297  00        129700  Founex     CH       VD           3         (null)         Founex    VD          5717   2018-06-06 12:58:47  
*/
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bocages', 1296, 00, 129600, 'Coppet', 'CH', 'VD', 2, null, 'Coppet', 'VD', 5712, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bochattets', 1296, 00, 129600, 'Coppet', 'CH', 'VD', 1, null, 'Coppet', 'VD', 5712, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bochattets', 1296, 00, 129600, 'Coppet', 'CH', 'VD', 2, null, 'Coppet', 'VD', 5712, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bochattets', 1296, 00, 129600, 'Coppet', 'CH', 'VD', 3, null, 'Coppet', 'VD', 5712, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bosquets', 1297, 00, 129700, 'Founex', 'CH', 'VD', 1, null, 'Founex', 'VD', 5717, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bosquets', 1297, 00, 129700, 'Founex', 'CH', 'VD', 2, null, 'Founex', 'VD', 5717, current timestamp);
insert into vista.tbdpostfilestreet values (NEXT VALUE FOR VISTA.VISTA_SEQ, 'Chemin des Bosquets', 1297, 00, 129700, 'Founex', 'CH', 'VD', 3, null, 'Founex', 'VD', 5717, current timestamp);

select distinct(bfsnr) from vista.abdpostfilestreet where zip6=129600;
/*
5712  
5717 
*/

-- FT802:
select * from vista.tpvaddressbasic order by lastupdated desc;


select * from vista.tpvpartner where name='Seshadri' and firstname='Sanjana'; -- 16242064
select * from vista.tpvaddress where kpvpartid=16242064;
/*
TPVADRSID   KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
----------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
29980493    16242064   963169               213520     29980494   AddressTyp#WS  (null)     (null)     AppendixPo#V  2         2              (null)  N       AddressStr#CH  (null)        1998-01-14  2003-08-31  (null)         2018-06-09 08:45:11  
29980507    16242064   964383               859476     29980494   AddressTyp#WS  (null)     (null)     AppendixPo#V  12        12             (null)  N       AddressStr#CH  (null)        2003-09-01  2018-07-31  (null)         2018-08-06 16:12:30  
3476279078  16242064   3311900004           795099     29980494   AddressTyp#WS  (null)     (null)     AppendixPo#V  13        13             (null)  N       AddressStr#CH  (null)        2018-08-01  9999-12-31  (null)         2018-08-06 16:23:47  
*/
select * from vista.tpvaddressbasic where kpvadbaid in (213520, 859476, 795099);
/*
TPVADBAID  KPVADBAID  STREET                 STREETSX  UPPERSTREET            ZIP     CITY     CITYSX  UPPERCITY  CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  --------  ---------------------  ------  -------  ------  ---------  ---------  ----------  -------  ----------  ----------  -------------------  
213518     213520     Schuppisstrasse        S123      SCHUPPISSTRASSE        805700  ZÃƒÆ’Ã‚Â¼rich   Z620    ZÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¦Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¡ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬Ãƒâ€¦Ã‚Â¡ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¦ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Â ÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¡ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â‚¬Å¡Ã‚Â¬Ãƒâ€šÃ‚Â¦ÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¢ÃƒÆ’Ã‚Â¢ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡Ãƒâ€šÃ‚Â¬ÃƒÆ’Ã¢â‚¬Â¦ÃƒÂ¢Ã¢â€šÂ¬Ã…â€œRICH     Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:28:08  
859472     859476     In der Gandstrasse     I536      IN DER GANDSTRASSE     812600  Zumikon  Z525    ZUMIKON    Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2012-04-03 15:18:58  
795098     795099     chemin des Bochattets  C553      CHEMIN DES BOCHATTETS  129600  Coppet   C130    COPPET     Canton#VD  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:38:53  
*/

-- AIT401:

select * from vista.abdpostfilestreet; -- 201: resultate

UPDATE vista.TURUPIREGISTER SET statuscd=1, deathdate='2018-01-02', delivery_date='2018-08-20', lastupdated=CURRENT TIMESTAMP where new_nnss='7561256053354';

-- Mumien-Test
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 --fd.REC_IDE='1112610060001136023'
and var.parmname like 'IG_PV%'
with ur; -- 272528148

select count(fd.rec_ide) as cnt_urcn
from dope.dop_fd fd
join dope.dop_fd_var var on fd.id=var.id
where fd.createtime > '2018-08-01 00:00:00.000'
and (var.parmname='DOPDOCID' and var.value like 'IG_PV_URCN%');

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 10 days and f.HDR_IDE like 'IG_PV_URCN_V';

select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in ('1822620540005313049')
and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_DRUCK_DEZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_PDF_ABLAGE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID', 'IG_ARCHIVIERUNG')
with ur;

select p.name, p.cpartnertype, p.personid, rr.crelationtype from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source)
left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid)
where rr.crelationtype='RoleRelati#GV' and exists (
    select 1 from vista.tpvrole r2 where r2.kpvpartid = p.kpvpartid and croletype like '%#RE'
) and p.validto > current date;

-- POLG - Canton
-- Prod ZH:
select * from vista.tpvpartner where clegaltype like '%POLG'; -- POLG --> CCANTON
select kpvpartid, name, additionalname, clegaltype, ccanton, ccompfundtype, cmunauthorcanton, lastupdated from vista.tpvpartner where cmunauthorcanton is not null; -- AK --> CMUNAUTHORCANTON: CompoundFu#V, K -- = CCOMPFUNDTYPE: CompoundFu#K

select kpvpartid, name, additionalname, clegaltype, ccanton, ccompfundtype, cmunauthorcanton, lastupdated from vista.tpvpartner where clegaltype like '%POLG' order by lastupdated desc; -- POLG --> CCANTON = Canton#SG, CMUNATHORCANTON = NULL
select kpvpartid, name, additionalname, clegaltype, ccanton, ccompfundtype, cmunauthorcanton, lastupdated from vista.tpvpartner where clegaltype like '%AK'; -- AK --> CCANTON mostly NULL, CMUNATHORCANTON = CompoundFu#K
select kpvpartid, name, additionalname, clegaltype, ccanton, ccompfundtype, cmunauthorcanton, lastupdated from vista.tpvpartner where clegaltype like '%AHVZ'; -- AK --> CCANTON mostly NULL, CMUNATHORCANTON = CompoundFu#K

-- AIT101
-- AK:
select kpvpartid, name, additionalname, clegaltype, ccanton, ccompfundtype, ccompfundfaktype, cmunauthorcanton, lastupdated from vista.tpvpartner order by lastupdated desc; --> AK: CCANTON
select * from vista.tpvpartner order by lastupdated desc;


-- xxx - ZH - Gemeindefusionen 2018 (180 auf 171)
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (munauthornr in (180, 171) and clegaltype in ('NNPersonTy#POLG', 'NNPersonTy#NNP')) or kpvpartid = 210283947
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
-- PROD:
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                               ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ---------------------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
963168     963169     173208452              Gemeinde Stadt ZÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rich              (null)          NNPersonTy#POLG  171          (null)       FLGAllocat#T   261             1900-01-01  9999-12-31  2017-09-13 09:22:22  
210283946  210283947  210279815              *Politische Gemeinde Stadt ZÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rich  (null)          NNPersonTy#NNP   (null)       (null)       (null)         (null)          1900-01-01  9999-12-31  2018-08-20 16:39:18  */
-- EDU:
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                              ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  --------------------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
963168     963169     173208452              Gemeinde Stadt ZÃƒÆ’Ã‚Â¼rich             (null)          NNPersonTy#POLG  171          (null)       FLGAllocat#T   261             1900-01-01  9999-12-31  2017-09-13 09:22:22  
210283946  210283947  210279815              Politische Gemeinde Stadt ZÃƒÆ’Ã‚Â¼rich  (null)          NNPersonTy#POLG  180          (null)       FLGAllocat#G   (null)          1900-01-01  9999-12-31  2011-07-18 08:37:39  
*/

WITH x AS (
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated
from vista.tpvpartner where ahvbranchnr in (180, 171) and clegaltype='NNPersonTy#AHVZ'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x ) order by kpvpartid, ahvbranchnr;
-- PROD = EDU
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME              ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ----------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
173208451  173208452  (null)                 AHV-Zweigstelle   ZÃƒÆ’Ã‚Â¼rich (VL)     NNPersonTy#AHVZ  (null)       171          (null)         (null)          1900-01-01  9999-12-31  2011-10-04 13:16:54  
210279814  210279815  (null)                 *AHV-Zweigstelle  ZÃƒÆ’Ã‚Â¼rich (VB)     NNPersonTy#AHVZ  (null)       180          (null)         (null)          1900-01-01  9999-12-31  2018-08-22 12:17:15  
*/

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, p.kpvpartid_ahvbranchnr, 
(select max(p2.ahvbranchnr) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid_ahvbranchnr) as ahv_no_partner,
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p4.munauthornr) from vista.tpvpartner p4 where p4.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype='AddressTyp#WS')
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    p.kpvpartid_ahvbranchnr in (210279815) or 
    a.kpvpartid_munauthor in (210283947) or 
    t.kpvpartid_taxdomicile in (210283947) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;

select * from vista.tpvpartner where name like 'Zahnarztpraxis%';
select * from vista.tpvpartner where kpvpartid=46054116;
select * from vista.tpvelarpid where kpvpartid=46054116;


-- 179443 / Defect 7919 - eduGL - NullPointer auf AG-Rolle
/*
Weitere intensive Analysen haben gezeigt:
- Das Problem ist nicht ein GL Problem, auf der SIT417 wurde auf SG Mandant getestet, und ist dort reproduzierbar.
- Es gibt zwei unterschiedliche Fehler, entweder kommt die nicht sprechende Fehlermeldung wobei die Daten geladen werden im GUI, aber die Adresse wird nicht angezeigt, obwohl im Kurzregister vorhanden.
- Oder die Daten werden ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼berhaupt nicht geladen im GUI, obwohl in der Datenbank die dazugehÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶rigen Kurzregister vorhanden sind.
- Bei NPs haben wir bis jetzt keine falschen DatensÃƒÆ’Ã‚Â¼tze gefunden.
*/
select p.name, p.kpvpartid, p.cpartnertype, p.clegaltype, r.croletype, r.ccontrgroup, r.active, ea.billnbr, ea.kpvpartner, ea.adr1, uid from vista.tpvrole r 
left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid)
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NNP' and r.croletype='Rolle#AG' and p.clegaltype <> 'NNPersonTy#POLG' and p.validto='9999-12-31'
and ea.billnbr is not null -- SIT435 - aborted after 45 min runtime...
fetch first 100 rows only;
-- SIT430
-- Gemeinde Gommiswald --> Fehler, 2 Abr.-Nr.
-- SIT435 - P.12.47.001 - ZH:
-- GALENOS: Fehler, AG-Rolle = aktiv, EA: NULL
-- ATRIA GmbH: Fehler, AG-Rolle = inaktiv, EA: NULL
-- Neuer Partner: AG-Rollentest, GB
select * from vista.tpvpartner where name='AG-Rollentest'; -- 3529879234
select * from vista.tpvrole where kpvpartid=3529879234;
select * from vista.tpvrole order by lastupdated desc; -- mutiert auf AG - Ohne Fehler.
select * from vista.tpvpartner where name='GALENOS'; -- 26012348
select * from vista.tpvrole where kpvpartid=26012348; -- VB-Rolle auf BW mutieren
update vista.tpvrole set croletype='Rolle#BW', lastupdated=current timestamp where kpvroleid=694573941;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
26012362    26012363    26012348   Rolle#STA  (null)     (null)       (null)  1900-01-01  9999-12-31  2008-10-23 11:13:48  
694573940   694573941   26012348   Rolle#BW   (null)     (null)       (null)  1900-01-01  9999-12-31  2018-09-21 13:04:30  
3518170591  3518170590  26012348   Rolle#AG   (null)     (null)       (null)  1995-01-01  9999-12-31  2018-09-14 10:29:00  
*/
-- Div. Fehler im GUI --> Rolle auf SE ÃƒÆ’Ã‚Â¼ndern:
update vista.tpvrole set croletype='Rolle#SE', lastupdated=current timestamp where kpvroleid=694573941; --> Gleiche Exception.
--> Folge: Muss an Personen-Daten liegen.
select * from vista.tikemployerarchive where kpvpartner=26012348; -- empty
select * from vista.tikemployerarchive where UPPER(adr1) like 'GALENOS%';
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1     ADR2               ADR3  ADR4         KPVCORRADDRESS  UID           CREGISTERCODE   CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE  LASTUPDATED          
----------  -------  ----------  -----------  -------  -----------------  ----  -----------  --------------  ------------  --------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  -----------  -------------------  
1225025336  L92839   (null)      BRANCHE#44   GALENOS  MilitÃƒÆ’Ã‚Â¼rstrasse 36        8004 ZÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rich  32295053        CHE107295914  ERFASSTCOD#812  RECHTSFORM#L  EADMINCODE#N  173029990017139       247593580201316   173029990019647       247593580201316           1995-01-01  9999-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2015-11-21 12:57:58  
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=26012348;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME   VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  -----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
56589405     26012347       26012348       1900-01-01        9999-12-31      TPVEDV2000PARTNER  0                         TPARTNER            247593580201316  2008-10-23 11:13:48  2008-10-23 20:30:38  
56589406     26012347       26012348       1900-01-01        9999-12-31      TPVPARTNER         0                         TFIRMA              247593580201316  2018-06-10 11:45:52  2018-06-10 11:47:32  
56589407     26012347       26012348       1900-01-01        9999-12-31      TPVFIRMATYPE       0                         TFIRMATYPE          247593580201316  2011-02-25 07:03:59  2011-02-25 07:04:28  
*/
--> Test: IK-Employerarchive abhÃƒÆ’Ã‚Â¼ngen:
update vista.tikemployerarchive set edv2000partnerid=NULL, lastupdated=current timestamp where tikearcid=1225025336; -- old value: 247593580201316
--> No Exceptions!
-- Reset:
update vista.tikemployerarchive set edv2000partnerid=247593580201316, lastupdated=current timestamp where tikearcid=1225025336;
-- Now, remove attributes until exception disappears.
update vista.tikemployerarchive set CREGISTERCODE=NULL, lastupdated=current timestamp where tikearcid=1225025336;
-- Still exception.
update vista.tikemployerarchive set CBRANCHCODE=NULL, lastupdated=current timestamp where tikearcid=1225025336;
-- Still exception.
update vista.tikemployerarchive set CEADMINCODE=NULL, lastupdated=current timestamp where tikearcid=1225025336; -- not nullable!
update vista.tikemployerarchive set CLEGALFORM=NULL, lastupdated=current timestamp where tikearcid=1225025336;
-- Still exception.
update vista.tikemployerarchive set KPVCORRADDRESS=NULL, lastupdated=current timestamp where tikearcid=1225025336;
-- NO EXCEPTION!!!!!
select * from vista.tpvaddress where kpvadrsid=32295053;
/*
TPVADRSID   KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1                  APPENDIX2              CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
----------  ---------  -------------------  ---------  ---------  -------------  -------------------------  ---------------------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
32295052    26012348   (null)               343451     32295053   AddressTyp#ZA  z.Hd. Herr Lang H.P.       (null)                 AppendixPo#V  19        19             (null)  N       AddressStr#CH  (null)        1900-01-01  2010-03-16  (null)         2010-03-17 09:42:14  
126936629   26012348   (null)               501381     32295053   AddressTyp#ZA  c/o Emmanuel Champredonde                         AppendixPo#V  1E        1E             (null)  N       AddressStr#CH  (null)        2010-03-17  2013-10-31  (null)         2013-11-29 10:34:01  
1137711999  26012348   (null)               338961     32295053   AddressTyp#ZA  VERTRAULICH / PERSÃƒÆ’Ã¢â‚¬â€œNLICH   Emmanuel Champredonde  AppendixPo#V  36        36             (null)  N       AddressStr#CH  (null)        2013-11-01  2014-10-31  (null)         2014-11-14 06:26:14  
1479980790  26012348   (null)               338961     32295053   AddressTyp#ZA  VERTRAULICH / PERSÃƒÆ’Ã¢â‚¬â€œNLICH   Roland Kleiner         AppendixPo#V  36        36             (null)  N       AddressStr#CH  (null)        2014-11-01  9999-12-31  (null)         2014-11-14 06:26:14  
*/
--> Now reproduce it on AIT101:
select * from vista.tikemployerarchive where validto='9999-12-31'; -- Lanaflor AG (Billnbr = 580308)
select * from vista.tikemployerarchive where validto='9999-12-31' and billnbr='580308';
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1         ADR2                  ADR3                ADR4           KPVCORRADDRESS  UID     CREGISTERCODE  CLEGALFORM  CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID  KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE  TOWNSHIP  CMEMBERTYPE  LASTUPDATED          
---------  -------  ----------  -----------  -----------  --------------------  ------------------  -------------  --------------  ------  -------------  ----------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  -------------  ----------  --------------  ------------------  ------------  --------  -----------  -------------------  
1050005    580308   (null)      BRANCHE#42   Lanaflor AG  z.H. Herr Kellerhans  Hubertusstrasse 18  8953 Dietikon  (null)          (null)  (null)         (null)      EADMINCODE#N  (null)                1051005           (null)                (null)                    1976-01-01  9999-12-31  (null)         (null)      (null)          (null)              (null)        (null)    (null)       2006-02-16 09:26:58  
*/
select * from vista.tpvrole where croletype='Rolle#IV' order by lastupdated desc;
/*
TPVROLEID        KPVROLEID        KPVPARTID         CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------------  ---------------  ----------------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
30005806         30005807         9000010001200005  Rolle#IV   (null)     (null)       (null)  2018-09-21  9999-12-31  2018-09-21 14:29:03  
*/
update vista.tpvrole set croletype='Rolle#AG', lastupdated=current timestamp where kpvroleid=30005807;
select * from vista.tpvaddress where kpvpartid=9000010001200005;
/*
TPVADRSID         KPVPARTID         KPVPARTID_MUNAUTHOR  KPVADBAID         KPVADRSID         CADDRESSTYPE   APPENDIX1             APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
----------------  ----------------  -------------------  ----------------  ----------------  -------------  --------------------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
9000010001200005  9000010001200005  (null)               9000010001200005  9000010001200005  AddressTyp#GS  z.H. Herr Kellerhans  (null)     AppendixPo#V  18        18             (null)  G       AddressStr#CH  (null)        1976-01-01  9999-12-31  (null)         2006-02-16 09:26:58  
*/
update vista.tikemployerarchive set kpvcorraddress=9000010001200005, lastupdated=current timestamp where tikearcid=1050005;


select * from vista.tikemployerarchive;


-- Mumien-Re-Test
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 and fd.REC_IDE='1826110430033321467'
--and var.value like 'IG_IK_IKPK%'
with ur;

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 10 days and f.HDR_IDE like 'IG_IK_IKPK_V';

select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 and fd.REC_IDE='1825411190033315835'
--and var.value like 'IG_IK_IKPK%'
with ur;

select distinct fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 and fd.REC_IDE in ('1825411190033315835', '1826110430033321467')
and var.PARMNAME in ('DOPTEMPLATEID', 'DOPDOCSTAT', 'IG_DRUCK_ZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PRIORITY', 'IG_ELAR_VISTA_DOC_REF', 'IG_ELAR_PID', 'IG_DRUCK')
order by fd.REC_IDE, var.PARMNAME
with ur;
/*
REC_IDE              PARMNAME               VALUE                
-------------------  ---------------------  -------------------  
1825411190033315835  DOPDOCSTAT             FINISHED             
1825411190033315835  DOPTEMPLATEID          IG_IK_IKPK_V         
1825411190033315835  IG_DRUCK               Z                    
1825411190033315835  IG_DRUCK_ZENTRAL       J                    
1825411190033315835  IG_ELAR_PID            393960996            
1825411190033315835  IG_ELAR_VISTA_DOC_REF  VDR5410030033315803  
1825411190033315835  IG_EXPRESSDRUCK        N                    
1825411190033315835  OS_PRIORITY            1                    
1826110430033321467  DOPDOCSTAT             RELEASED             
1826110430033321467  DOPTEMPLATEID          IG_PV_URCN_V         
1826110430033321467  IG_DRUCK               Z                    
1826110430033321467  IG_DRUCK_ZENTRAL       J                    
1826110430033321467  IG_ELAR_PID            385840930            
1826110430033321467  IG_ELAR_VISTA_DOC_REF  VDR6110430033321466  
1826110430033321467  IG_EXPRESSDRUCK        J                    
1826110430033321467  OS_PRIORITY            0                    
*/


select count(distinct a.kpvadrsid) from vista.tpvaddress a
where a.validfrom >= '2018-07-31' 
and not exists (
    select 1 from vista.tbikeymapping2000 bi where bi.vista_kpv_key = a.kpvadrsid
);

select p.name, p.firstname, p.personid, a.* from vista.tpvaddress a
left join vista.tpvpartner p on (p.kpvpartid = a.kpvpartid and p.validto >= current date)
where a.validfrom >= '2018-07-31' 
and not exists (
    select 1 from vista.tbikeymapping2000 bi where bi.vista_kpv_key = a.kpvadrsid
);

select p.name, p.firstname, p.personid from vista.tpvpartner p
where p.lastupdated >= '2018-07-31' 
and not exists (
    select 1 from vista.tbikeymapping2000 bi where bi.vista_kpv_key = p.kpvpartid
);

select * from VISTA.TEIMESSAGEREFERENCE
where MESSAGESTATUS = 'EIMSGST#COMPLETED' -- 'EIMSGST#FAILED' / 'EIMSGST#COMPLETED'
and TEMPLATEID like 'IG_%' -- <--- change to your needs...
and lastupdated > '2018-07-23 20:00:00.000' and lastupdated < '2018-09-26 06:00:00.000'; -- <--- change to your needs..

-- TemporÃƒÆ’Ã‚Â¼re Partner
select count(*) as cnt_tmp, temp from vista.tpvpartner where cpartnertype like '%#NP' group by temp order by count(*) desc;
-- ProdZH:
/*
CNT_TMP  TEMP    
-------  ------  
6462255  N       
91480    (null)  
16667    Y       
*/
-- ProdSG:
/*
CNT_TMP  TEMP    
-------  ------  
2284367  N       
37364    (null)  
65       J       
*/
-- ProdZG:
/*
CNT_TMP  TEMP    
-------  ------  
868662   N       
1        (null)  
*/
-- ProdTG:
/*
CNT_TMP  TEMP    
-------  ------  
978033   N       
13445    (null)  
11574    Y       
*/
-- Case from logged defect (SG):
select * from vista.tpvpartner where personid='7569766236458'; -- Temp = N
-- Journal data:
select * from vista.jpvpartner_archive_cc0452 j where j.kpvpartid in (
    select kpvpartid from vista.tpvpartner where cpartnertype like '%#NP' and temp in ('J', NULL)
); -- jpvpartner: 0, jpvpartner_archive_cc0520: 1 (IK:IKJUKDB301:1519148575), jpvpartner_archive_cc0493: 2 (IKJUKDB301), jpvpartner_archive_cc0452: NON-APPL SQL (2010-09-22 13:11:34)


-- Deleted partners
select * from vista.jpvpartner where operation='I';
select substring(j.program, 4, 40) as program, count(*) as cnt_del from vista.jpvpartner j where j.operation='D' and not exists (
    select 1 from vista.kpvpartner k where k.kpvpartid = j.kpvpartid
) group by substring(j.program, 4, 40) order by count(*) desc;
-- SG:
/*
PROGRAM                CNT_DEL  
---------------------  -------  
null                   11       
IKJMEBB102:1618877907  2        
*/
-- ZH:
/*
PROGRAM                CNT_DEL  
---------------------  -------  
null                   3        
IKJMEBB102:3525430088  1        
*/

select substring(program, 4, 12) as program, count(*) as cnt_del from vista.jpvpartner_archive_cc0520 where operation='D' group by substring(program, 4, 12) order by count(*) desc;
select substring(j.program, 4, 12) as program, count(*) as cnt_del from vista.jpvpartner_archive_cc0520 j where j.operation='D' and not exists (
    select 1 from vista.kpvpartner k where k.kpvpartid = j.kpvpartid
) group by substring(j.program, 4, 12) order by count(*) desc;
-- SG:
/*
PROGRAM       CNT_DEL  
------------  -------  
null          148      
IKJMEBB102:1  23       
PV-Dlg-701 D  1        
*/
-- ZH:
/*
PROGRAM       CNT_DEL  
------------  -------  
null          57       
IKJMEBB102:3  21       
*/   

-- ZG - Zu langer vorname
-- 'GEORGINA CONSTANZA MARIA MACARENA KATHARINA'
select * from vista.tpvpartner where upper(firstname) like 'GEORGINA CONSTANZA MARIA MACARENA%';
select * from vista.tikrequestheader where pendfirstname like 'GEORGINA CONSTANZA MARIA MACARENA%';
select tikrqheid, tikvaikreqid, pendvnr, pendfirstname, change_date, change_user, program, operation from vista.jikrequestheader where pendvnr='7563970202674';


-- 185844 - SO - L&Z Daten werden von L&Z nicht in Host ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼bertragen
select * from vista.tpvpartner where personid='7569360008895'; -- 66066926
select * from vista.tpvaddress where kpvpartid=66066926; -- 693423478
select a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.appendix1, a.streetnr, ab.street, ab.zip, ab.city from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid) where a.kpvadrsid=693423478;
/*
KPVADRSID  TPVADRSID  CADDRESSTYPE   APPENDIX1                       STREETNR  STREET       ZIP     CITY       
---------  ---------  -------------  ------------------------------  --------  -----------  ------  ---------  
693423478  693423477  AddressTyp#ZA  Textiles & modisches Gestalten  20        Bielstrasse  450000  Solothurn  
*/
select * from vista.jpvaddress where kpvadrsid=693423478;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1                            APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                OPERATION  
---------  ---------  -------------------  ---------  ---------  -------------  -----------------------------------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  -------------------  -----------  ---------------------  ---------  
693423477  66066926   (null)               467091     693423478  AddressTyp#ZA  NatÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rlich K Textiles&mod. Gest.      (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-09-13  9999-12-31  (null)         2018-09-13 12:40:16  2018-09-13 12:40:16  SO5584       PV:PV-Dlg-301 Adresse  I          
693423477  66066926   (null)               467091     693423478  AddressTyp#ZA  NatÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rlich K Textiles&mod. Gest.      (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-09-13  9999-12-31  (null)         2018-09-13 12:40:16  2018-09-18 10:39:09  SO3014       PV:PV-Dlg-301 Adresse  U          
693423477  66066926   (null)               467091     693423478  AddressTyp#ZA  NatÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rlich K Textiles&mod. Gestalten  (null)     AppendixPo#V  20        20             (null)  N       AddressStr#CH  (null)        2018-09-13  9999-12-31  (null)         2018-09-18 10:39:09  2018-09-19 08:54:03  SO1358       PV:PV-Dlg-301 Adresse  U          
*/
select * from vista.tbikeymapping2000 where vista_kpv_key=693423478;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
693423772    693423477      693423478      2018-09-13        9999-12-31      TPVADDRESS        0                         TADRESSIERUNG       985544567309387  2018-09-19 08:56:02  2018-09-19 08:56:35  
*/
select * from vista.tbiprocessed_uow where vista_kpv_key=693423478;
/*
TBIPROCUOWID  IBMSNAP_COMMITSEQ                 IBMSNAP_INTENTSEQ                 VISTA_TABLE_NAME  PROCESSING_STATE  VISTA_KPV_KEY  LASTUPDATED          
------------  --------------------------------  --------------------------------  ----------------  ----------------  -------------  -------------------  
693423753     0000000000DFA052000000FA25619462  000000000000000000000118F478A9B2  TPVADDRESS        P                 693423478      2018-09-13 12:41:15  
694178592     0000000000F0934E000000FA29370669  00000000000000000000011B2D705B65  TPVADDRESS        P                 693423478      2018-09-18 10:39:51  
694377290     0000000000F458EC000000FA29FC5479  00000000000000000000011BA34B3C50  TPVADDRESS        P                 693423478      2018-09-19 08:56:04  
*/

-- UPI und Dummy-NNSS
select * from vista.aurupiregister where new_nnss like '756000000%' order by new_nnss;
select count (distinct new_nnss) from vista.aurupiregister where new_nnss like '756000000%'; -- 35

-- 190849 - SO - ZIK-Archivieren Button funzt nicht
select * from vista.tikcollection;

select * from VISTA.TEIMESSAGEREFERENCE
where 1=1 --MESSAGESTATUS = 'EIMSGST#COMPLETED' -- 'EIMSGST#FAILED' / 'EIMSGST#COMPLETED'
and TEMPLATEID like 'IG_%' -- <--- change to your needs...
and lastupdated > '2018-10-12 11:00:00.000' and lastupdated < '2018-10-12 20:00:00.000';
/*
TEIMSGREFID  MESSAGEID            MESSAGEPRIORITY   MESSAGESTATUS  MESSAGETYPE  MESSAGETRETIRES  ELARJOBID  CPRINTSTATUS         TEMPLATEID    USERID       ORIGIN       CARCHIVESTATUS      DOCUMENTCREATION     LASTUPDATED          
-----------  -------------------  ----------------  -------------  -----------  ---------------  ---------  -------------------  ------------  -----------  -----------  ------------------  -------------------  -------------------  
30006111     1828511040000036425  EIMSGPRIO#ONLINE  EIMSGST#NEW    OS           0                (null)     EIPRINTST#COMPLETED  IG_IK_KOAU_V  SGLOGIN:001  APP129_IK-:  EIMSGEST#COMPLETED  2018-10-12 11:04:19  2018-10-12 11:04:17  
*/
select distinct fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 and fd.REC_IDE in ('1828511040000036425')
and var.PARMNAME in ('DOPTEMPLATEID', 'DOPDOCSTAT', 'IG_DRUCK_ZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PRIORITY', 'IG_ELAR_VISTA_DOC_REF', 'IG_ELAR_PID', 'IG_DRUCK', 'IG_ARCHIVIERUNG', 'IG_ELAR_PID')
order by fd.REC_IDE, var.PARMNAME
with ur;
/*
REC_IDE              PARMNAME               VALUE                
-------------------  ---------------------  -------------------  
1828511040000036425  DOPDOCSTAT             FINISHED             
1828511040000036425  DOPTEMPLATEID          IG_IK_KOAU_V         
1828511040000036425  IG_ARCHIVIERUNG        J                    
1828511040000036425  IG_DRUCK_ZENTRAL       N                    
1828511040000036425  IG_ELAR_PID            9000010001058347     
1828511040000036425  IG_ELAR_VISTA_DOC_REF  VDR8511040000036423  
1828511040000036425  IG_EXPRESSDRUCK        J                    
1828511040000036425  OS_PRIORITY            2                    
*/
/*
Leider konnten wir das Problem bislang nicht nachstellen und bitten um ein Problem-Ticket.
Wir haben auf AIT bei einer vollstÃƒÆ’Ã‚Â¼ndigen IK-Sammlung im Dialog IK-Dlg-304 auf "ZIK archivieren" geklickt, "Druck Kontoauszug" gewÃƒÆ’Ã‚Â¼hlt und auf "AusfÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼hren" geklickt. Danach haben wir den Status in der EI-Tabelle und im Dope untersucht und festgestellt, dass fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r den Testpartner der OS-Request foglende Werte aufwies:
DOPDOCSTAT FINISHED
DOPTEMPLATEID IG_IK_KOAU_V
IG_ARCHIVIERUNG J
GemÃƒÆ’Ã‚Â¼ss Beschreibung scheinen nicht alle AuszÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ge betroffen zu sein. WÃƒÆ’Ã‚Â¼re es mÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶glich, dass die Kasse Beispiele liefert fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r erfolgreich archivierte AuszuÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ge und fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r nicht erfolgreiche?
*/
/*
GemÃƒÆ’Ã‚Â¼ss RÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ckmeldung vom Fachbereich hat es am Freitag mit dem Archivieren wieder geklappt.

 

Beim nÃƒÆ’Ã‚Â¼chsten Mal werden wir die FÃƒÆ’Ã‚Â¼lle notieren und eine entsprechende RÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ckmeldung ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ber das Problemtickt 192004 machen.
*/

-- 191815 - SO - ZIK-Druck Direkt" gedruckt wird, muss dieser gleichzeitig archiviert werden.
select * from vista.tikcollection;
-- 756.0183.5115.62
--> IG-Dlg-304 --> ZIK-Druck direkt
select * from VISTA.TEIMESSAGEREFERENCE
where 1=1 --MESSAGESTATUS = 'EIMSGST#COMPLETED' -- 'EIMSGST#FAILED' / 'EIMSGST#COMPLETED'
and TEMPLATEID like 'IG_%' -- <--- change to your needs...
and lastupdated > '2018-10-15 11:00:00.000' and lastupdated < '2018-10-15 20:00:00.000';
/*
TEIMSGREFID  MESSAGEID            MESSAGEPRIORITY   MESSAGESTATUS  MESSAGETYPE  MESSAGETRETIRES  ELARJOBID  CPRINTSTATUS         TEMPLATEID    USERID       ORIGIN       CARCHIVESTATUS      DOCUMENTCREATION     LASTUPDATED          
-----------  -------------------  ----------------  -------------  -----------  ---------------  ---------  -------------------  ------------  -----------  -----------  ------------------  -------------------  -------------------  
30001520     1828814380000036467  EIMSGPRIO#ONLINE  EIMSGST#NEW    OS           0                (null)     EIPRINTST#COMPLETED  IG_IK_KOAU_V  SGLOGIN:001  APP129_IK-:  EIMSGEST#COMPLETED  2018-10-15 14:38:17  2018-10-15 14:38:21  
*/
select distinct fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where 1=1 and fd.REC_IDE in ('1828814380000036467')
and var.PARMNAME in ('DOPTEMPLATEID', 'DOPDOCSTAT', 'IG_DRUCK_ZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PRIORITY', 'IG_ELAR_VISTA_DOC_REF', 'IG_ELAR_PID', 'IG_DRUCK', 'IG_ARCHIVIERUNG', 'IG_ELAR_PID')
order by fd.REC_IDE, var.PARMNAME
with ur;
/*
REC_IDE              PARMNAME               VALUE                
-------------------  ---------------------  -------------------  
1828814380000036467  DOPDOCSTAT             FINISHED             
1828814380000036467  DOPTEMPLATEID          IG_IK_KOAU_V         
1828814380000036467  IG_ARCHIVIERUNG        J                    
1828814380000036467  IG_DRUCK_ZENTRAL       N                    
1828814380000036467  IG_ELAR_PID            9000010001050245     
1828814380000036467  IG_ELAR_VISTA_DOC_REF  VDR8814370000036465  
1828814380000036467  IG_EXPRESSDRUCK        J                    
1828814380000036467  OS_PRIORITY            2                    
*/

-- UPI-Abgleich - No Workload 15.10.2018
select * from vista.tpvdynamicparams where paramname='PVJURCON_START';
/*
TPVDYNPARAMID  PARAMNAME       PARAMVALUET          PARAMVALUES  LASTUPDATED          
-------------  --------------  -------------------  -----------  -------------------  
1590749199     PVJURCON_START  2018-10-15 00:00:00  (null)       2018-10-15 20:55:09  
*/
select * from vista.tiklastbatchrun;
/*
BATCHRUNID  TIKBATCHID  LASTSUCCESSFULEXECDATE  LASTUPDATED          
-----------------  ----------  ----------------------  -------------------  
1                  IKJUKDB301  2018-10-15              2018-10-15 20:52:31
*/
select * from vista.jiklastbatchrun order by change_date desc;
/*
TIKLASTBATCHRUNID  TIKBATCHID  LASTSUCCESSFULEXECDATE  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                   OPERATION  
-----------------  ----------  ----------------------  -------------------  -------------------  -----------  ------------------------  ---------  
1                  IKJUKDB301  2018-10-12              2018-10-12 20:52:40  2018-10-15 20:52:31  SGIK0A01     IK:IKJUKDB301:1667607290  U          
*/
select * from vista.jikheader where change_date >= '2018-10-15' and program like '%IKJUKDB301%';
/*
TIKHEADID   TIKOWNRID   VNR            NAME                             BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                   OPERATION  
----------  ----------  -------------  -------------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  -------------------  -----------  ------------------------  ---------  
1049651282  1049651281  7560209035317  NOSER,DANIELA ELWINA             1980       1           2         SEXCODEZAS#2  BSVLAND#100  68580502184    T                2016-07-26 20:40:03  2018-10-15 20:52:33  SGIK0A01     IK:IKJUKDB301:1667607290  U          
594896840   594896839   7560996060059  FLORIC,ANDREA                    1996       1           26        SEXCODEZAS#2  BSVLAND#100  34796526159    F                2014-02-03 20:38:10  2018-10-15 20:52:41  SGIK0A01     IK:IKJUKDB301:1667607290  U          
80066968    76788956    7561169760110  PLJEVALJCIC,SUZANA               1981       12          2         SEXCODEZAS#2  BSVLAND#100  68481864317    F                2017-01-05 20:36:14  2018-10-15 20:52:43  SGIK0A01     IK:IKJUKDB301:1667607290  U          
(...)
*/

-- 191909 - ZH - Message in BOQ: LZ.IK-RR003
/*
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns7:IGS-IKAbfrageArbeitnehmerRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0016/2" xmlns:ns4="https://igs-gmbh.ch/xmlns/igs-0015/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2" xmlns:ns6="https://igs-gmbh.ch/xmlns/igs-0014/2" xmlns:ns5="https://igs-gmbh.ch/xmlns/igs-0017/2" xmlns:ns8="https://igs-gmbh.ch/xmlns/igs-0021/2" xmlns:ns7="https://igs-gmbh.ch/xmlns/igs-0020/2" xmlns:ns13="https://igs-gmbh.ch/xmlns/igs-0008/2" xmlns:ns9="https://igs-gmbh.ch/xmlns/igs-0091/2" xmlns:ns12="https://igs-gmbh.ch/xmlns/igs-0114/2" xmlns:ns11="https://igs-gmbh.ch/xmlns/igs-0093/2" xmlns:ns10="https://igs-gmbh.ch/xmlns/igs-0090/2">
    <head>
        <senderId>eadmin</senderId>
        <initiatedSenderId>eadmin</initiatedSenderId>
        <messageID>61be822c-67e5-46fa-8a96-a5a6c77dbdc7</messageID>
        <message>
            <type>0020</type>
            <version>2.0</version>
        </message>
        <sendingApplication>
            <sendingProduct>eadmin-agap</sendingProduct>
            <sendingProductVersion>3.8.2.1-240135854-prod</sendingProductVersion>
        </sendingApplication>
        <messageDate>2018-10-10T16:57:32.605+02:00</messageDate>
        <tenant>ZH</tenant>
    </head>
    <ns7:body>
        <ns7:billNumber>A26905</ns7:billNumber>
        <ns7:contributionYearStart>2013</ns7:contributionYearStart>
        <ns7:contributionYearEnd>2018</ns7:contributionYearEnd>
    </ns7:body>
</ns7:IGS-IKAbfrageArbeitnehmerRequest>
*/
/*
2018-10-10 11:05:04,565 ERROR (IkQueryEmployeeMsgBean) - COSI000015|ERROR|IK|LZ.IK-RR003-V2|DEFAULT|ZH|ZHIK0A01|null|0||||Service was not executed successfully. 
Service Response: [ProcessQueryIkEmployeeQueueServiceResponse: 
Name: com.ibm.vista.ik.asl.booking.response.impl.ProcessQueryIkEmployeeQueueServiceResponse| 
Code: IKREQ00801| Message: Vista Message: {Message Code: [IKREQ00801],Message Level: [40000],
Message Text: [VNR length is incorrect.],Default Message Text: [VNR length is incorrect.],Message Parameters: [],
Exception Messages: [[com.ibm.vista.common.exceptions.VistaExceptionDSL:VNR length is incorrect.]],
Stacktrace: [VistaFunctionalException: VNR length is incorrect. 
Message Text: VNR length is incorrect. 
Message Code: IKREQ00801 Level : 40000 at com.ibm.vista.ik.dsl.provider.util.UtilValidation.validateVnrStructure(UtilValidation.java:1176) 
at com.ibm.vista.ik.dsl.provider.validator.IkOwnerDSPValidator.preValidateFindAccountOwnerByVNR(IkOwnerDSPValidator.java:396) 
at com.ibm.vista.ik.dsl.provider.impl.IkOwnerDSP.findAccountOwnerByVNR(IkOwnerDSP.java:448) 
at com.ibm.vista.ik.asl.provider.realizer.IkBookingASPRealizer.processQueryIkEmployeeQueueService(IkBookingASPRealizer.java:2622) 
at com.ibm.vista.ik.asl.provider.impl.IkBookingASP.processQueryIkEmployeeQueueService(IkBookingASP.java:1384) 
at com.ibm.vista.ik.mq.LZIKRR003.V2.IkQueryEmployeeMsgBean.processMqMessage(IkQueryEmployeeMsgBean.java:115)
*/
-- DAO: processFindVNRListfromBillNoforQueryEmployee()
select distinct(hd.vnr) from  vista.tikheader hd 
inner join vista.tikaccount acc on (hd.TIKHEADID=acc.TIKHEADID) 
INNER JOIN vista.tikbooking book ON (book.TIKACCTID=acc.TIKACCTID) 
inner join vista.TIKPERIOD bkp on (book.TIKBOPEID = bkp.TIKBOPEID)
and book.BILLNBR = 'A26905'
and ( (year(bkp.BEGINDATE)>='2013' and year(bkp.ENDDATE)<='2018')
    or (bkp.refYear>='2013' and bkp.refYear<='2018'))
and book.cemployeecode ='YESNO#J'
and (book.clastaction != 'IKBUCHHIST#d' or book.clastaction is NULL );
/*
20185767117    
7560002858328  
7560002941679  
7560003634082  
7560004127507  
7560006649359  
(...)
*/ -- @15 sec
select count(distinct(hd.vnr)) from  vista.tikheader hd 
inner join vista.tikaccount acc on (hd.TIKHEADID=acc.TIKHEADID) 
INNER JOIN vista.tikbooking book ON (book.TIKACCTID=acc.TIKACCTID) 
inner join vista.TIKPERIOD bkp on (book.TIKBOPEID = bkp.TIKBOPEID)
and book.BILLNBR = 'A26905'
and ( (year(bkp.BEGINDATE)>='2013' and year(bkp.ENDDATE)<='2018')
    or (bkp.refYear>='2013' and bkp.refYear<='2018'))
and book.cemployeecode ='YESNO#J'
and (book.clastaction != 'IKBUCHHIST#d' or book.clastaction is NULL );
-- 8444
-- processFindPendVnrForBillNumberForQueryEmployee()
select unique(booking.pendvnr) from vista.tikbooking booking 
inner join vista.TIKPERIOD period on (booking.TIKBOPEID = period.TIKBOPEID)
where (booking.TIKACCTID = '10000' or booking.TIKACCTID = '10001')
and booking.BILLNBR = 'A26905'
and ( (year(period.BEGINDATE)>='2013' and year(period.ENDDATE)<='2018')
    or (period.refYear>='2013' and period.refYear<='2018'))
and booking.cemployeecode ='YESNO#J'
and (booking.clastaction != 'IKBUCHHIST#d' or booking.clastaction is NULL );
/*
00000000000  
*/
-------> Andere Events fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r ein anderes Problem... .

-- Suche der Message ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ber Zeit und Content:
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR003' and lastupdated > '2018-10-10 16:57:20' and lastupdated < '2018-10-10 16:57:50';
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR003' and lastupdated > '2018-10-10 12:55:00' and lastupdated < '2018-10-10 19:59:00' and inboundmsg like '%A26905%'; -- empty
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR003' and lastupdated > '2018-10-10 12:55:00' and lastupdated < '2018-10-10 19:59:00' and outboundmsg like '%A26905%'; -- empty
-- Splunk:
/*
2018-10-10 16:57:32,870 INFO  (IkQueryEmployeeMsgBean) - MQMSGACC|INFO|IK|LZ.IK-RR003-V2|DEFAULT|ZH|zhdummy|null|0||||MQ [LZ.IK-RR003] 
MessageID [ID:414d5120414258325a485020202020201f3ba85b23cc7d96] - Accepted
2018-10-10 16:57:32,854 INFO  (IkQueryEmployeeMsgBean) - MQMSGREC|INFO|IK|LZ.IK-RR003-V2|DEFAULT|ZH|zhdummy|null|0||||MQ [LZ.IK-RR003] 
MessageID [ID:414d5120414258325a485020202020201f3ba85b23cc7d96] - Received
2018-10-10 16:57:32,838 INFO (IkQueryEmployeeMsgBean) - MQMSGLOGR|INFO|IK|LZ.IK-RR003-V2|DEFAULT|ZH|zhdummy|null|0||||JMSType [LZ.IK-RR003] - 
messageID [61be822c-67e5-46fa-8a96-a5a6c77dbdc7] - referenceMessageID [] - businessProcessID [] - 
JMSMessageID [ID:414d5120414258325a485020202020201f3ba85b23cc7d96] - JMSCorrelationID []
*/
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR003' and jmsmessageid='ID:414d5120414258325a485020202020201f3ba85b23cc7d96'; -- found.
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE      JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID  JMSDESTINATION                                 JMSREPLYTO                                     BUSINESSPROCESSID  TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            LASTUPDATED          
--------------  ------  ------  ---------------  -----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ----------------  ---------------------------------------------  ---------------------------------------------  -----------------  --------  ------  --------  ----------------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
3599956668      0       (null)  JMSTextMessage   LZ.IK-RR003  2                0              4            ID:414d5120414258325a485020202020201f3ba85b23cc7d96  1539183452730  (null)            queue://ABX2ZHP/EA.LZIK.RR003.INITIALLOAD.REQ  queue://ABX2ZHP/EA.LZIK.RR003.INITIALLOAD.REP  (null)             ZH        (null)  ZHIK0A01  de                <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
*/
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR003' and jmsmessageid='ID:414d5120414258325a485020202020201f3ba85b23cc7d96'; -- empty


-- Defect 57034 - Im Warnfeld werden die mÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶glichen POLG-Treffer nicht angezeigt.
/*
IST:
Bei der Erfassung der Adresse: Bruggwaldstrasse, 9008 St. Gallen erscheint beim Speichern der Warnhinweis " FÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r WS und GS Adressen muss eine polit. Gemeinde ( POLG ) gesetzt sein. Vorgeschlagene Gemeinde (n) gemÃƒÆ’Ã‚Â¼ss Strassenverzeichnis:"
- Es werden keine POLG's angezeigt.

SOLL:
Im Warnhinweis mÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ssen folgende POLG's angezeigt werden:
- St. Gallen 3203
- Wittenbach 3204
*/
select * from vista.tpvaddressbasic where upperstreet='BRUGGWALDSTRASSE' and zip='900800';
/*
TPVADBAID  KPVADBAID  STREET            STREETSX  UPPERSTREET       ZIP     CITY        CITYSX  UPPERCITY   CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ----------------  --------  ----------------  ------  ----------  ------  ----------  ---------  ----------  -------  ----------  ----------  -------------------  
494648     494650     Bruggwaldstrasse  B624      BRUGGWALDSTRASSE  900800  St. Gallen  S324    ST. GALLEN  Canton#SG  Country#CH  N        1900-01-01  9999-12-31  2008-06-19 09:09:48  
*/
select distinct bfsnr, polgname from vista.abdpostfilestreet where upper(street)='BRUGGWALDSTRASSE' and zip6='900800';
/*
BFSNR  POLGNAME    
-----  ----------  
3203   St. Gallen  
3204   Wittenbach  
*/

select * from vista.tiscmcode where company_shortcode='PV' and code_id like '%PV00820180';
/*
CODETYPENO  CODENO    CODE_ID             SHORTCODE   COMPANY_SHORTCODE  XML_TAG  SORT_ID  CONST_FIELD        VALUE  VALID_FROM           VALID_TO             CUSER     CDATE                UUSER     UTST                 
----------  --------  ------------------  ----------  -----------------  -------  -------  -----------------  -----  -------------------  -------------------  --------  -------------------  --------  -------------------  
1000132     42996379  MSGTYPE#PV00820180  PV00820180  PV                 (null)   1        MSG_PV_1000820_18         1900-01-01 00:00:00  9999-12-31 23:59:59  cmmaster  2018-10-07 22:17:27  cmmaster  2018-10-07 22:17:27  
*/
select * from vista.tiscmcode_descr where codeno=42996379;
/*
CODETYPENO  CODENO    LANGUAGE  SHORT_DESCRIPT                  MEDIUM_DESCRIPT                                                                                                                                                  LONG_DESCRIPT                                                                                                                                                    CUSER     CDATE                UUSER     UTST                 
----------  --------  --------  ------------------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------  --------  -------------------  --------  -------------------  
1000132     42996379  4         PV00820180                      For WS and GS addresses a municipal authority (POLG) needs to assigned. Please assign the correct municipal authority first.   Suggested municipal authorities:  For WS and GS addresses a municipal authority (POLG) needs to assigned. Please assign the correct municipal authority first.   Suggested municipal authorities:  cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996379  1         PV00820180                      FÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r WS and GS Adressen muss eine polit. Gemeinde (POLG) gesetzt sein. Vorgeschlagene Gemeinde(n) gemÃƒÆ’Ã‚Â¼ss Strassenverzeichnis:                                     FÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r WS and GS Adressen muss eine polit. Gemeinde (POLG) gesetzt sein. Vorgeschlagene Gemeinde(n) gemÃƒÆ’Ã‚Â¼ss Strassenverzeichnis:                                     cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996379  3         PV00820180                      Per questi indirizzi (WS, GS) deve essere stabilito un comune politico (POLG). Suggerimenti:                                                                     Per questi indirizzi (WS, GS) deve essere stabilito un comune politico (POLG). Suggerimenti:                                                                     cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996379  2         PV00820180                      Une municipalitÃƒÆ’Ã‚Â© politique (POLG) doit ÃƒÆ’Ã‚Âªtre dÃƒÆ’Ã‚Â©finie pour adresses WS et GS. Suggestions:                                                                         Une municipalitÃƒÆ’Ã‚Â© politique (POLG) doit ÃƒÆ’Ã‚Âªtre dÃƒÆ’Ã‚Â©finie pour adresses WS et GS. Suggestions:                                                                         cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
*/
update vista.tiscmcode_descr set medium_descript = CONCAT(medium_descript, '{0}, {1} (BfS-Nr.: {2})'), 
long_descript = CONCAT(medium_descript, '{0}, {1} (BfS-Nr.: {2})') where short_descript='PV00820180' and codeno=42996379;

select * from vista.tiscmcode where company_shortcode='PV' and code_id like '%PV00820190';
/*
CODETYPENO  CODENO    CODE_ID             SHORTCODE   COMPANY_SHORTCODE  XML_TAG  SORT_ID  CONST_FIELD        VALUE  VALID_FROM           VALID_TO             CUSER     CDATE                UUSER     UTST                 
----------  --------  ------------------  ----------  -----------------  -------  -------  -----------------  -----  -------------------  -------------------  --------  -------------------  --------  -------------------  
1000132     42996438  MSGTYPE#PV00820190  PV00820190  PV                 (null)   1        MSG_PV_1000820_19         1900-01-01 00:00:00  9999-12-31 23:59:59  cmmaster  2018-10-07 22:17:27  cmmaster  2018-10-07 22:17:27  
*/
select * from vista.tiscmcode_descr where codeno=42996438;
/*
CODETYPENO  CODENO    LANGUAGE  SHORT_DESCRIPT                  MEDIUM_DESCRIPT                                                                                                                                                               LONG_DESCRIPT                                                                                                                                                                 CUSER     CDATE                UUSER     UTST                 
----------  --------  --------  ------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------  --------  -------------------  --------  -------------------  
1000132     42996438  4         PV00820190                      According to Swiss Post data, for the provided address data a different municipal authority (POLG) should be used.   Please check the suggested municipal authorities below:  According to Swiss Post data, for the provided address data a different municipal authority (POLG) should be used.   Please check the suggested municipal authorities below:  cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996438  1         PV00820190                      GemÃƒÆ’Ã‚Â¼ss Strassenverzeichnis sollte fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r diese Adresse eine andere polit. Gemeinde (POLG) gesetzt werden, bitte ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼berprÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼fen Sie Ihre Wahl.   VorschlÃƒÆ’Ã‚Â¼ge:                          GemÃƒÆ’Ã‚Â¼ss Strassenverzeichnis sollte fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r diese Adresse eine andere polit. Gemeinde (POLG) gesetzt werden, bitte ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼berprÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼fen Sie Ihre Wahl.   VorschlÃƒÆ’Ã‚Â¼ge:                          cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996438  3         PV00820190                      Secondo l' elenco stradale, per questo indirizzo dovrebbe essere impostato un altro comune politico (POLG), si prega di controllare la vostra scelta.   Indicazioni:          Secondo l' elenco stradale, per questo indirizzo dovrebbe essere impostato un altro comune politico (POLG), si prega di controllare la vostra scelta.   Indicazioni:          cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
1000132     42996438  2         PV00820190                      Selon l'annuaire des rues, une municipalitÃƒÆ’Ã‚Â© politique (POLG) diffÃƒÆ’Ã‚Â©rente devrait ÃƒÆ’Ã‚Âªtre utilisÃƒÆ’Ã‚Â©e pour cette adresse. Veuillez cocher votre choix.   Suggestions:                 Selon l'annuaire des rues, une municipalitÃƒÆ’Ã‚Â© politique (POLG) diffÃƒÆ’Ã‚Â©rente devrait ÃƒÆ’Ã‚Âªtre utilisÃƒÆ’Ã‚Â©e pour cette adresse. Veuillez cocher votre choix.   Suggestions:                 cmmaster  2018-10-07 22:17:33  cmmaster  2018-10-07 22:17:33  
*/
update vista.tiscmcode_descr set medium_descript = CONCAT(medium_descript, '{0}, {1} (BfS-Nr.: {2})'), 
long_descript = CONCAT(medium_descript, '{0}, {1} (BfS-Nr.: {2})') where short_descript='PV00820190' and codeno=42996438;


-- UPI-Abgleich
select * from vista.tpvpartner where personid='7562265702967';
/*
TPVPARTID   KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE   SOCIALSECNR  TITEL   NAME     NAMESX  UPPERNAME  FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE   BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE  CLEGALFORM  CSEX   ADDITIONALNAME  UPPERADDITIONALNAME  CCANTON  COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID       CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS         TEMP  ISVIC   VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          RESIDAUTHORTO  
----------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  -------------  -----------  ------  -------  ------  ---------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ----------  -------------  ------------  ----------------  ------------  ----------  ----------  -----  --------------  -------------------  -------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  -------------  -----------  --------------  ----------------  --------------------  ------------  ----------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  --------------  ----  ------  ----------  ----------  --------  -------------  -------------------  -------------  
72072602    72072604   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  89989612159  (null)  TURECEK  T622    TURECEK    SABRINA    S165         SABRINA         TURECEK   TURECEK        (null)     (null)          NameHyphen#Y   CorresLang#D  1989-04-12  0              (null)        (null)            Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#LI    (null)            7562265702967  (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       DATA MIGRATION  N     (null)  1989-04-12  2018-10-16  (null)    (null)         2018-10-17 20:41:06  (null)         
1669787830  72072604   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  89989612159  (null)  ROELKE   R420    ROELKE     SABRINA    S165         SABRINA         ROELKE    ROELKE         (null)     (null)          NameHyphen#Y   CorresLang#D  1989-04-12  0              (null)        (null)            Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        (null)        (null)            7562265702967  (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       DATA MIGRATION  N     (null)  2018-10-17  9999-12-31  (null)    (null)         2018-10-17 20:41:06  (null)         
*/
select * from vista.jpvpartner where kpvpartid=72072604;
/*
TPVPARTID   KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE   SOCIALSECNR  TITEL   NAME     NAMESX  UPPERNAME  FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE   BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE  CLEGALFORM  CSEX   ADDITIONALNAME  UPPERADDITIONALNAME  CCANTON  COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID       CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS         TEMP  ISVIC   VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          RESIDAUTHORTO  CHANGE_DATE          CHANGE_USER  PROGRAM                   OPERATION  
----------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  -------------  -----------  ------  -------  ------  ---------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ----------  -------------  ------------  ----------------  ------------  ----------  ----------  -----  --------------  -------------------  -------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  -------------  -----------  --------------  ----------------  --------------------  ------------  ----------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  --------------  ----  ------  ----------  ----------  --------  -------------  -------------------  -------------  -------------------  -----------  ------------------------  ---------  
1669787830  72072604   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  89989612159  (null)  ROELKE   R420    ROELKE     SABRINA    S165         SABRINA         ROELKE    ROELKE         (null)     (null)          NameHyphen#Y   CorresLang#D  1989-04-12  0              (null)        (null)            Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        (null)        (null)            7562265702967  (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       DATA MIGRATION  N     (null)  2018-10-17  9999-12-31  (null)    (null)         2018-10-17 20:41:06  (null)         2018-10-17 20:41:06  SGIK0A01     IK:IKJUKDB301:1669778843  I          
72072602    72072604   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  89989612159  (null)  TURECEK  T622    TURECEK    SABRINA    S165         SABRINA         TURECEK   TURECEK        (null)     (null)          NameHyphen#Y   CorresLang#D  1989-04-12  0              (null)        (null)            Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#LI    (null)            7562265702967  (null)       (null)          (null)            (null)                (null)        (null)            (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       DATA MIGRATION  N     (null)  1989-04-12  9999-12-31  (null)    (null)         2010-09-22 11:30:32  (null)         2018-10-17 20:41:06  SGIK0A01     IK:IKJUKDB301:1669778843  U          
*/

-- 191937 - AI - Neue Bank Raiffeisen Neukirch-Romanshorn
select * from vista.tpvbankbasic where clearingnr='81398';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME                        ADDRESS1               ADDRESS2  ZIP     CITY               BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ------------------------------  ---------------------  --------  ------  -----------------  --------  ----------  ----------  ----------  -------------------  
1129356    1129357    (null)   81398       Raiff.bank Romanshorn           Alleestrasse 31        (null)    859000  Romanshorn         0         Country#CH  1998-06-12  2001-05-31  2009-11-26 00:14:30  
1129358    1129357    (null)   81398       Raiff.bank Neukirch-Romanshorn  Amriswilerstrasse 2 a  (null)    931500  Neukirch (Egnach)  0         Country#CH  2001-06-01  9999-12-31  2018-10-11 14:01:21  
*/
select * from vista.jpvbankbasic where clearingnr='81398';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME                        ADDRESS1         ADDRESS2  ZIP     CITY        BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                     OPERATION  
---------  ---------  -------  ----------  ------------------------------  ---------------  --------  ------  ----------  --------  ----------  ----------  ----------  -------------------  -------------------  -----------  ------------------------------------------  ---------  
1129356    1129357    (null)   81398       Raiff.bank Romanshorn           Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  1998-06-12  9999-12-31  2009-11-26 00:14:30  2009-11-26 00:14:30  Migration    PV                                          I          
1129356    1129357    (null)   81398       Raiff.bank Romanshorn           Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  1998-06-12  9999-12-31  2009-11-26 00:14:30  2009-11-26 00:14:30  Migration    PV                                          U          
1129358    1129357    (null)   81398       Raiff.bank Neukirch-Romanshorn  Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  2001-06-01  2001-06-01  2009-11-26 00:14:30  2009-11-26 00:14:30  Migration    PV                                          I          
1129356    1129357    (null)   81398       Raiff.bank Romanshorn           Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  1998-06-12  2001-06-01  2009-11-26 00:14:30  2009-11-26 00:14:30  Migration    PV                                          U          
1129358    1129357    (null)   81398       Raiff.bank Neukirch-Romanshorn  Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  2001-06-01  2001-06-01  2009-11-26 00:14:30  2015-02-26 14:52:20  aiwk         PV:PV-Dlg-70800 Dialog Periode Bankenstamm  U          
1129358    1129357    (null)   81398       Raiff.bank Neukirch-Romanshorn  Alleestrasse 31  (null)    859000  Romanshorn  0         Country#CH  2001-06-01  9999-12-31  2015-02-26 14:52:20  2018-10-11 14:01:21  aiwk         PV:PV-Dlg-510 Bankenstamm                   U          
*/

select kpvpartid, count(distinct croletype) from vista.tpvrole group by kpvpartid order by 2 desc;
select * from vista.tpvrolerel;
select * from vista.tpvpartner where titel like 'Dr.%' and cpartnertype='PartnerTyp#NP';
select kpvroleid_source, count(distinct crelationtype) from vista.tpvrolerel where kpvadrsid_corr is not null and crelationtype='RoleRelati#KE' group by kpvroleid_source order by 2 desc;
select * from vista.tpvrole where kpvpartid=168005197;
select * from vista.tpvrolerel where kpvroleid_source in (select kpvroleid from vista.tpvrole where kpvpartid=168005197);

-- 192147 - SZ - Partnerdatenabgleich PV - ELAR
select kpvpartid, tpvpartid, name, firstname, personid, validfrom, validto, lastupdated from vista.tpvpartner where personid='7560700945948';
/*
KPVPARTID  TPVPARTID  NAME     FIRSTNAME  PERSONID       VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ---------  -------------  ----------  ----------  -------------------  
2261577    2261629    De Vito  Elvira     7560700945948  2009-04-20  2018-09-06  2018-09-17 10:54:45  
2261577    491395233  von Euw  Elvira     7560700945948  2018-09-07  9999-12-31  2018-10-19 16:11:30  
*/
select * from vista.tpvaddress where kpvpartid=2261577;
select * from vista.tpvpartnerreplication where kpvpartid=2261577;
/*
TPVPARTREPID  KPVPARTID  VALIDFROM   CTARGETAPPL    CSTATUS             CREATIONRUN  CREATIONTIME         REPLICATIONRUN  REPLICATIONTIME      LASTUPDATED          
------------  ---------  ----------  -------------  ------------------  -----------  -------------------  --------------  -------------------  -------------------  
499382562     2261577    2018-09-07  BusinessAp#EI  RepState#PROCESSED  499382466    2018-10-19 16:15:32  (null)          (null)               2018-10-19 16:15:34  
499382566     2261577    2018-09-07  BusinessAp#AI  RepState#PROCESSED  499382466    2018-10-19 16:15:32  (null)          (null)               2018-10-19 16:15:52  
499382560     2261577    2018-09-07  BusinessAp#AS  RepState#PROCESSED  499382466    2018-10-19 16:15:32  499385151       2018-10-19 16:29:39  2018-10-19 16:29:39  
491395473     2261577    2018-09-07  BusinessAp#EI  RepState#PROCESSED  491395391    2018-09-17 10:55:25  (null)          (null)               2018-09-17 10:55:26  
491395476     2261577    2009-04-20  BusinessAp#AI  RepState#PROCESSED  491395391    2018-09-17 10:55:25  (null)          (null)               2018-09-17 10:56:45  
491395477     2261577    2018-09-07  BusinessAp#AI  RepState#PROCESSED  491395391    2018-09-17 10:55:25  (null)          (null)               2018-09-17 10:56:45  
*/

-- 192667 - GL - Error in IKJB10102 (null in bookingdelivered)
-- 53108cb7-aedf-4192-bb6f-0239794395a8
/*
2018-10-22 20:39:01,824 ERROR (IkOutgoingCollectionMessagesASPRealizer) - 
ZA0920004a|ERROR|IK|IKJB10102|DEFAULT|GL|GLIK0A01|53108cb7-aedf-4192-bb6f-0239794395a8|0|extRunId=33204989|runId=264331287|workItemKey=262182440|
Mandatory fields not set: [[rc:Informationsteil]]

2018-10-22 20:39:01,824 ERROR (IkOutgoingCollectionMessagesBPC) - BC20001005|ERROR|IK|IKJB10102|DEFAULT|GL|GLIK0A01|53108cb7-aedf-4192-bb6f-0239794395a8|0|extRunId=33204989|
runId=264331287|workItemKey=262182440|WI processing Error, changes rolled back, key [262182440], 
type [IKJB10102_EXPCOLLDEL (IKWITYPE#IKJB10102)], result [IKWIERROR (BATCHRES#IKWIERROR)], aspMessage [VistaMessage{Code [ZA0920004a], Level [40000], 
Text [ZA0920004a], Parameters: [[rc:Informationsteil]]}]
*/
/*
calculateOutgoingCollectionMessages()
// fetch all ZIKExecutions ready for transmission
    Long[] _IkZIKExecutionIdList = getIkZIKExecutionDSP()
        .findAllZikExecutionsReadyForTransmission();
        
        _ZikExecutions = getIkZIKExecutionDAO()
        .processFindExecutedZikExecutionsByTransmissionDate(null);
*/

select distinct execution.tikzexcid from vista.tikzikexecution as execution,
vista.tikzikorder as zorder where zorder.tikziorid = execution.tikziorid
and zorder.CSz <> 'SZMZR#99' and execution.executionDate is NOT NULL and execution.transmissiondate is NULL and execution.tikcollId_actual is NULL;
/*
262182440  
262182846 
*/

select distinct execution.tikzexcid from vista.tikzikexecution as execution,
vista.tiksplittingexecution as spexe, vista.tiksplittingorder as spOrder where 
(execution.TIKSEXCID_LEAD1 = spexe.tiksexcid or execution.TIKSEXCID_LEAD2 = spexe.tiksexcid) 
and spOrder.TIKSPORID = spexe.TIKSPORID
and spOrder.CSz <> 'SZMZR#99' and execution.executionDate is NOT NULL and execution.transmissiondate is NULL and execution.tikcollId_actual is NULL;
/*
33896094   
35124375   
36177677   
37248387   
37753474   
37753485   
41704654   
(...)
*/
select * from vista.tikzikexecution where tikzexcid in (262182440, 262182846);
/*
TIKZEXCID  TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME         BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
---------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  --------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
262182440  262182439  (null)           (null)           (null)            (null)            0            0                    8      0      7569000270699  YEMANE,FIKADU   0                        0                      0               2018-10-04     GLIK0A01    1          2018-10-03    0                             2018-10-04 20:44:54  
262182846  262182845  (null)           (null)           (null)            (null)            0            0                    8      0      7565984760300  MUSTAFA,YALMAZ  0                        0                      0               2018-10-04     GLIK0A01    1          2018-10-03    0                             2018-10-04 20:45:14  
*/
-- http://195.141.159.89:8000/de-DE/app/search-igs/search?q=search%20%22%7CGL%7C%22%20IKJB10102%20%22workItemKey%3D262182440%22&earliest=-7d%40h&latest=now&sid=1540297928.14737
--> 262182440 / 262182846 immer error!
select * from vista.tzaxmlmzrrecord where lastupdated >= current date - 7 days and recorddata like '%7569000270699%'; -- empty
select * from vista.tzaxmlmzrrecord where lastupdated >= current date - 7 days and recorddata like '%Informationsteil%'; -- IKMessage
/*
// Find ZIK Execution by Id
      IIkZIKExecutionDE ikZIKExecutionDE = getIkZIKExecutionDSP()
          .findZikExecutionById(pBatchWorkItemKey);
      if (null != ikZIKExecutionDE) {
        if (null != ikZIKExecutionDE.getTikziorid()) {
          // Find ZIKOrder by OrderId
          ikZikOrderDE = getIkZIKOrderDSP().findZIKOrderByOrderID(
              ikZIKExecutionDE.getTikziorid());
          if (ikZIKExecutionDE.getAddendumik()) {
            lIsZikTransferZas = isZikExecutionAddendumExportToZas(ikZikOrderDE,
                transferDate);
          } // End If
          */
select * from vista.tikzikorder where tikziorid=262182439;
/*
TIKZIORID  TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE              VNR            VNRNAME        VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA   VNRLANAME  CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
---------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------------------  -------------  -------------  -------------  ----------------  -----------  ------------------  --------------  ------  ---------  ----------------------  -----------------------  -------------------  
262182439  (null)             255753640  2018-10-03  SZMZR#98  8           0           0               599         0           SAN905-7569000270699  7569000270699  YEMANE,FIKADU  (null)         2018-10-03        2018-12-01   ZAS                 (null)          (null)  (null)     (null)                  (null)                   2018-10-04 20:41:39  
*/
/*
if (lIsZikTransferZas || lIsSplittingTransferZas) {
          IIkBookingDeliveredDEList ikBookingDeliveredDEList = getIkBookingDeliveredDSP()
              .findBookingDeliveredByZikExecutionId(ikZIKExecutionDE.getId());
              */
-- Fall 1:
select * from vista.tikbookingdelivered where tikzexcid=262182440;
/*
TIKBODVID  TIKZEXCID  TIKBOPEID  TIKEXECPROVID  BILLZIP  BILLDESCR      INCOME   BILLNBR        CCONTRIBUTIONTYPE  CBUSINESSSECTOR  CCARETAKINGFACTOR  CSPECIALCASE  CAMORTISATIONCODE  CSTORNOCODE  LASTUPDATED          
---------  ---------  ---------  -------------  -------  -------------  -------  -------------  -----------------  ---------------  -----------------  ------------  -----------------  -----------  -------------------  
262189207  262182440  262189206  (null)         (null)   Yemane Fikadu  1556.00  10000187       SZBEITRART#4       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-10-04 20:44:54  
262189210  262182440  262189209  (null)         (null)   Yemane Fikadu  4667.00  10000187       SZBEITRART#4       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-10-04 20:44:54  
262189213  262182440  262189212  (null)         (null)   null           2723.00  10000187       SZBEITRART#4       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-10-04 20:44:54  
*/
select distinct begindate, enddate, refyear, beginmonth, endmonth from vista.tikperiod where tikbopeid in (select tikbopeid from vista.tikbookingdelivered where tikzexcid=262182440 and billdescr='null');
/*
BEGINDATE  ENDDATE  REFYEAR  BEGINMONTH  ENDMONTH  
---------  -------  -------  ----------  --------  
(null)     (null)   2015     6           12        
*/
select billnbr, validfrom, validto, kpvpartner from vista.tikemployerarchive where billnbr='10000187';
/*
BILLNBR   VALIDFROM   VALIDTO     KPVPARTNER  
--------  ----------  ----------  ----------  
10000187  2015-06-01  2017-04-30  255750410   
*/
select kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where kpvpartid=255750410;
/*
KPVPARTID  NAME    FIRSTNAME  VALIDFROM   VALIDTO     
---------  ------  ---------  ----------  ----------  
255750410  Yemane  Fikadu     2016-12-06  9999-12-31 
*/

-- Fall 2:
select * from vista.tikbookingdelivered where tikzexcid=262182846;
/*
TIKBODVID  TIKZEXCID  TIKBOPEID  TIKEXECPROVID  BILLZIP  BILLDESCR       INCOME    BILLNBR        CCONTRIBUTIONTYPE  CBUSINESSSECTOR  CCARETAKINGFACTOR  CSPECIALCASE   CAMORTISATIONCODE  CSTORNOCODE  LASTUPDATED          
---------  ---------  ---------  -------------  -------  --------------  --------  -------------  -----------------  ---------------  -----------------  -------------  -----------------  -----------  -------------------  
262190368  262182846  262190367  (null)         (null)   Mustafa Yalmaz  1556.00   10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190371  262182846  262190370  (null)         (null)   Mustafa Yalmaz  -1556.00  10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#1   2018-10-04 20:45:14  
262190374  262182846  262190373  (null)         (null)   Mustafa Yalmaz  1556.00   10000140       SZBEITRART#4       (null)           (null)             SONDERFALL#01  (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190377  262182846  262190376  (null)         (null)   Mustafa Yalmaz  4667.00   10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190380  262182846  262190379  (null)         (null)   Mustafa Yalmaz  -4667.00  10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#1   2018-10-04 20:45:14  
262190383  262182846  262190382  (null)         (null)   Mustafa Yalmaz  4667.00   10000140       SZBEITRART#4       (null)           (null)             SONDERFALL#01  (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190386  262182846  262190385  (null)         (null)   null            4667.00   10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190389  262182846  262190388  (null)         (null)   null            -4667.00  10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#1   2018-10-04 20:45:14  
262190392  262182846  262190391  (null)         (null)   null            4667.00   10000140       SZBEITRART#4       (null)           (null)             SONDERFALL#01  (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190395  262182846  262190394  (null)         (null)   null            4667.00   10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190398  262182846  262190397  (null)         (null)   null            -4667.00  10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#1   2018-10-04 20:45:14  
262190401  262182846  262190400  (null)         (null)   null            4667.00   10000140       SZBEITRART#4       (null)           (null)             SONDERFALL#01  (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190404  262182846  262190403  (null)         (null)   null            1556.00   10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190407  262182846  262190406  (null)         (null)   null            1556.00   10000140       SZBEITRART#4       (null)           (null)             SONDERFALL#01  (null)             SZSTORNO#0   2018-10-04 20:45:14  
262190410  262182846  262190409  (null)         (null)   null            -1556.00  10000140       SZBEITRART#4       (null)           (null)             (null)         (null)             SZSTORNO#1   2018-10-04 20:45:14  
*/
select distinct begindate, enddate, refyear, beginmonth, endmonth from vista.tikperiod where tikbopeid in (select tikbopeid from vista.tikbookingdelivered where tikzexcid=262182846 and billdescr='null');
/*
BEGINDATE  ENDDATE  REFYEAR  BEGINMONTH  ENDMONTH  
---------  -------  -------  ----------  --------  
(null)     (null)   2013     9           12        
(null)     (null)   2014     1           12        
(null)     (null)   2015     1           12        
*/
select billnbr, validfrom, validto, kpvpartner from vista.tikemployerarchive where billnbr='10000140';
/*
BILLNBR   VALIDFROM   VALIDTO     KPVPARTNER  
--------  ----------  ----------  ----------  
10000140  2013-09-01  2017-04-30  251080639   
*/
select kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where kpvpartid=251080639;
/*
KPVPARTID  NAME     FIRSTNAME  VALIDFROM   VALIDTO     
---------  -------  ---------  ----------  ----------  
251080639  Mustafa  Yalmaz     2016-11-24  9999-12-31  
*/
--> Siehe auch Ticket 185841 (Analyse Kurt, DKA durch Andrea)
--> Neues Master-Ticket fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r GL: 191542


-- 191538 - TG - Error in IKJB10102 (null in bookingdelivered)
select * from vista.tikzikexecution where tikzexcid=826797950;
/*
TIKZEXCID  TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME        BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
---------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  -------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
826797950  826797949  (null)           (null)           (null)            (null)            0            0                    20     0      7568105802811  MENGIS,TESFAY  0                        0                      0               2018-10-04     TGIK0A01    1          2018-10-03    0                             2018-10-04 20:36:46  
*/
select * from vista.tikbookingdelivered where tikzexcid=826797950;
/*
TIKBODVID  TIKZEXCID  TIKBOPEID  TIKEXECPROVID  BILLZIP  BILLDESCR  INCOME   BILLNBR        CCONTRIBUTIONTYPE  CBUSINESSSECTOR  CCARETAKINGFACTOR  CSPECIALCASE  CAMORTISATIONCODE  CSTORNOCODE  LASTUPDATED          
---------  ---------  ---------  -------------  -------  ---------  -------  -------------  -----------------  ---------------  -----------------  ------------  -----------------  -----------  -------------------  
826835791  826797950  826835790  (null)         (null)   null       4667.00  10000775       SZBEITRART#4       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-10-04 20:36:46  
826835794  826797950  826835793  (null)         (null)   null       4667.00  10000775       SZBEITRART#4       (null)           (null)             (null)        (null)             SZSTORNO#0   2018-10-04 20:36:46  
*/
select distinct begindate, enddate, refyear, beginmonth, endmonth from vista.tikperiod where tikbopeid in (select tikbopeid from vista.tikbookingdelivered where tikzexcid=826797950 and billdescr='null');
/*
BEGINDATE  ENDDATE  REFYEAR  BEGINMONTH  ENDMONTH  
---------  -------  -------  ----------  --------  
(null)     (null)   2016     1           12        
(null)     (null)   2017     1           12        
*/
select billnbr, validfrom, validto, kpvpartner from vista.tikemployerarchive where billnbr='10000775';
/*
BILLNBR   VALIDFROM   VALIDTO     KPVPARTNER  
--------  ----------  ----------  ----------  
10000775  2016-01-01  9999-12-31  777039698   
*/
select kpvpartid, name, firstname, validfrom, validto from vista.tpvpartner where kpvpartid=777039698;
/*
KPVPARTID  NAME    FIRSTNAME  VALIDFROM   VALIDTO     
---------  ------  ---------  ----------  ----------  
777039698  Mengis  Tesfay     2018-06-20  9999-12-31  
*/


-- UngÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ltige NationalitÃƒÆ’Ã‚Â¼ten (DDR, Yugoslawien, Sowjetunion, ...)
select ccountry, count(*) as cnt_countries from vista.tikheader where ccountry in ('BSVLAND#208', 'BSVLAND#220', 'BSVLAND#235', 'BSVLAND#238', 'BSVLAND#531', 'BSVLAND#538') group by ccountry;
/*
CCOUNTRY     CNT_COUNTRIES  
-----------  -------------  
BSVLAND#208  1              
BSVLAND#220  66             
BSVLAND#235  20             
BSVLAND#238  3              
*/
select * from vista.tikheader where ccountry in ('BSVLAND#208', 'BSVLAND#220', 'BSVLAND#235', 'BSVLAND#238', 'BSVLAND#531', 'BSVLAND#538');

select distinct p.ccountryofliving as pv_countryofliving, p.ccitizenship as pv_citizenship,
(select d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id = p.ccitizenship) as pv_citizenship_name,
h.ccountry as ik_country,
(select d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id = h.ccountry) as bsv_country_name
from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid)
left join vista.tikowner o on (o.kpvroleid = r.kpvroleid)
left join vista.tikheader h on (h.tikownrid = o.tikownrid)
where h.ccountry in ('BSVLAND#208', 'BSVLAND#220', 'BSVLAND#235', 'BSVLAND#238', 'BSVLAND#531', 'BSVLAND#538');
/*
PV_COUNTRYOFLIVING  PV_CITIZENSHIP  PV_CITIZENSHIP_NAME            IK_COUNTRY   BSV_COUNTRY_NAME  
------------------  --------------  -----------------------------  -----------  ----------------  
Country#CH          Country#DE      Deutschland                    BSVLAND#208  DDR               
Country#DE          Country#DE      Deutschland                    BSVLAND#208  DDR               
Country#CH          Country#CH      Schweiz                        BSVLAND#538  Jemen             
(null)              Country#STU     Staatszugehörigkeit unbekannt  BSVLAND#538  Jemen             
Country#CH          Country#CH      Schweiz                        BSVLAND#238  Tschechoslowakei  
Country#CH          Country#STU     Staatszugehörigkeit unbekannt  BSVLAND#238  Tschechoslowakei  
(null)              Country#STU     Staatszugehörigkeit unbekannt  BSVLAND#238  Tschechoslowakei  
Country#CH          Country#CZ      Tschechische Republik          BSVLAND#238  Tschechoslowakei  
Country#CZ          Country#CZ      Tschechische Republik          BSVLAND#238  Tschechoslowakei  
*/





-- 192827 - SO - Neue Bank CIC
/*
Clearing-Nr.: 8710
Name: Bank CIC (SCHWEIZ) AG
Strasse/ Nr: Marktplatz 13
PLZ/ Ort: 4001 Basel
*/
select * from vista.tpvbankbasic where clearingnr='8710';
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME               ADDRESS1       ADDRESS2  ZIP     CITY   BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ---------------------  -------------  --------  ------  -----  --------  ----------  ----------  ----------  -------------------  
702792107  702792108  (null)   8710        Bank CIC (SCHWEIZ) AG  Marktplatz 13  (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2018-10-24 14:09:06  
*/
select * from vista.jpvbankbasic where clearingnr='8710';
/*
TPVBANKID  KPVBANKID  SWIFTNR      CLEARINGNR  BANKNAME               ADDRESS1    ADDRESS2  ZIP     CITY   BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                     OPERATION  
---------  ---------  -----------  ----------  ---------------------  ----------  --------  ------  -----  --------  ----------  ----------  ----------  -------------------  -------------------  -----------  ------------------------------------------  ---------  
4932249    4932250    (null)       8710        Bank CIAL              (null)      (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2009-03-05 01:21:55  2009-03-05 01:21:55  Migration    PV                                          I          
4932249    4932250    (null)       8710        Bank CIAL              (null)      (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2009-03-05 01:21:55  2011-10-28 11:40:23  SO8047       PV:PV-Dlg-504 Dialog Massenmutation BcNr    U          
38283678   4932250    CIALCHBBXXX  8710        Bank CIC (Schweiz) AG  (null)      (null)    400100  Basel  0         Country#CH  2011-10-01  9999-12-31  2011-10-31 09:59:32  2011-11-08 09:44:40  SO1358       PV:PV-Dlg-510 Bankenstamm                   U          
4932249    4932250    (null)       8710        Bank CIAL              (null)      (null)    400100  Basel  0         Country#CH  1900-01-01  2011-09-30  2011-10-28 11:40:23  2018-10-24 14:00:03  SO1358       PV:PV-Dlg-70800 Dialog Periode Bankenstamm  U          
702792107  702792108  (null)       8710        Bank CIC (SCHWEIZ) AG  Marktplatz  (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2018-10-24 14:01:32  2018-10-24 14:01:32  SO5584       PV:PV-Dlg-510 Bankenstamm                   I          
702792107  702792108  (null)       8710        Bank CIC (SCHWEIZ) AG  Marktplatz  (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2018-10-24 14:01:32  2018-10-24 14:09:06  SO5584       PV:PV-Dlg-510 Bankenstamm                   U          
*/
--> 2 verschiedene Banken
select * from vista.tpvbankbasic where kpvbankid=4932250;
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME               ADDRESS1  ADDRESS2  ZIP     CITY   BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------  ----------  ---------------------  --------  --------  ------  -----  --------  ----------  ----------  ----------  -------------------  
38283678   4932250    (null)   87105       Bank CIC (Schweiz) AG  (null)    (null)    400100  Basel  0         Country#CH  2011-10-01  9999-12-31  2018-10-25 07:20:18  
4932249    4932250    (null)   87105       Bank CIAL              (null)    (null)    400100  Basel  0         Country#CH  1900-01-01  2011-09-30  2018-10-24 14:00:03  
*/
--> Alte Bank: Mutation der Clearning-Nr. von 8710 auf 87105
select * from vista.jpvbankbasic where kpvbankid=702792108;
/*
TPVBANKID  KPVBANKID  SWIFTNR  CLEARINGNR  BANKNAME               ADDRESS1    ADDRESS2  ZIP     CITY   BRANCHID  CCOUNTRY    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                    OPERATION  
---------  ---------  -------  ----------  ---------------------  ----------  --------  ------  -----  --------  ----------  ----------  ----------  -------------------  -------------------  -----------  -------------------------  ---------  
702792107  702792108  (null)   8710        Bank CIC (SCHWEIZ) AG  Marktplatz  (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2018-10-24 14:01:32  2018-10-24 14:01:32  SO5584       PV:PV-Dlg-510 Bankenstamm  I          
702792107  702792108  (null)   8710        Bank CIC (SCHWEIZ) AG  Marktplatz  (null)    400100  Basel  0         Country#CH  1900-01-01  9999-12-31  2018-10-24 14:01:32  2018-10-24 14:09:06  SO5584       PV:PV-Dlg-510 Bankenstamm  U          
*/
-- Keymapping neue Bank:
select * from vista.tbikeymapping2000 where vista_kpv_key=702792108; -- empty
-- Keymapping alte Bank:
select * from vista.tbikeymapping2000 where vista_kpv_key=4932250;
/*
TBIKEYMAPID  VISTA_TPV_KEY  VISTA_KPV_KEY  VISTA_VALID_FROM  VISTA_VALID_TO  VISTA_TABLE_NAME  VISTA_BLOCK_BACK_MAPPING  EDV2000_TABLE_NAME  EDV2000_ZID_KEY  EDV2000_SYS_EIN_KEY  LASTUPDATED          
-----------  -------------  -------------  ----------------  --------------  ----------------  ------------------------  ------------------  ---------------  -------------------  -------------------  
648002205    38283678       4932250        1900-01-01        9999-12-31      TPVBANKBASIC      0                         TFIRMA              508075183209218  2018-03-28 14:23:52  2018-03-28 15:28:43  
*/
--> Nur eine Periode, funktioniert aber.
--> To do EDV2000:
-- a) Existierende Bank analog vista mutieren (Name, Adresse, insbes. Clearing-Nr. ÃƒÆ’Ã‚Â¼ndern von 8710 auf 87105.
-- b) Erstellung eines neuen Bankenstamms

-- Nachfrage:
select * from vista.tbikeymapping2000 where edv2000_zid_key=94996252802062; -- empty

-- MQ Partner replication: error categories
select distinct reason from vista.tsfmqoutbound; -- MQOUTINFO#REPNOTREQ


-- 193154 - GR - Gemeindefusionen Rheinwald
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (3961, 3693, 3694, 3714) or ahvbranchnr in (562, 603, 674, 746)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME              ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ----------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
959648     959650     37466697               Gemeinde Nufenen  (null)          NNPersonTy#POLG  603          (null)       FLGAllocat#T   3693            1900-01-01  9999-12-31  2013-07-29 17:11:53  
960395     960401     31548907               Gemeinde GrÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼sch   (null)          NNPersonTy#POLG  559          (null)       FLGAllocat#T   3961            1900-01-01  9999-12-31  2013-07-29 17:06:33  
29131031   961016     29118434               Gemeinde SplÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼gen  (null)          NNPersonTy#POLG  674          (null)       FLGAllocat#T   3694            1900-01-01  9999-12-31  2013-07-29 17:26:09  
*/
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where name like '%Rheinwald%' and clegaltype='NNPersonTy#POLG';

select * from vista.aurupiregister where  relcancellationcd is not null; -- civilstatuschange is not null or
select * from vista.tpvpartner;


-- 193644 - SG - PVJURCON - WI-Abort
select count(*) as cnt_updates from vista.aurupiregister where delivery_date = '2018-11-05'; -- 15001
select count(*) as cnt_updates from vista.aurupiregister upi where upi.delivery_date = '2018-11-05' and exists (
    select 1 from vista.tpvpartner where personid = upi.new_nnss
); -- 1024 ( > 1000er-Limite im CM)
select count(*) as cnt_updates_mini from vista.aurupiregister upi where upi.delivery_date = '2018-11-05' and exists (
    select p.kpvpartid, a.kpvadrsid from vista.tpvpartner p
    left join vista.tpvaddress a on a.kpvpartid = p.kpvpartid
    where p.personid = upi.new_nnss and a.kpvadrsid is not null and exists (
        select 1 from vista.tpvrole r where r.kpvpartid = p.kpvpartid and croletype not in ('Rolle#STA', 'Rolle#IK')
    )
); -- 479 (Partner zu geÃƒÆ’Ã‚Â¼ndertem UPI-File mit Adresse und mind. einer Rolle ausser STA und IK --> gÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ltig ab SR47)
-- Wurde "letzter erfolgreicher Batchlauf"-Parameter dennoch aktualisiert (erwartet: ja)?
select * from vista.tpvdynamicparams where paramname='PVJURCON_START';
/*
1590749199     PVJURCON_START  2018-11-08 00:00:00  (null)       2018-11-08 20:41:47
*/
-- Ja, Datum erfolgreich angepasst.


-- 193642 - SO - PVJURCON - WI-Abort
select count(*) as cnt_updates from vista.aurupiregister where delivery_date = '2018-11-05'; -- 15001
select count(*) as cnt_updates from vista.aurupiregister upi where upi.delivery_date = '2018-11-05' and exists (
    select 1 from vista.tpvpartner p where (p.personid = upi.new_nnss or p.personid = old_ahv_or_nnss) and p.validto > '2018-11-05'
); -- 927 ( < 1000er-Limite im CM)

-- 193643 - TG - PVJURCON - WI-Abort
select count(*) as cnt_updates from vista.aurupiregister where delivery_date = '2018-11-05'; -- 15001
select count(*) as cnt_updates from vista.aurupiregister upi where upi.delivery_date = '2018-11-05' and exists (
    select 1 from vista.tpvpartner p where (p.personid = upi.new_nnss or p.personid = old_ahv_or_nnss) and p.validto > '2018-11-05'
); -- 475 ( < 1000-limite in CM)

-- updated query by Divya (SG/TG) -- Extend it to more dates:
select count(*) as cnt_updates from vista.aurupiregister upi where upi.delivery_date in ('2018-11-02', '2018-11-03', '2018-11-04','2018-11-05') and exists (
    select 1 from vista.tpvpartner p where (p.personid = upi.new_nnss or p.personid = old_ahv_or_nnss)
and p.validfrom <='2018-11-05' and p.validto >= '2018-11-05'
); -- TG: 5290
select * from vista.tpvdynamicparams;


select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like ('%PVCONST_60')
order by c.value;


-- GR
select * from vista.tpvpartner where name='Gemeinde Rheinwald'; -- empty
select * from vista.tpvpartner where bfsmunitipalnr='3714';

-- Old countries in UPI / PV
select c.code_id, c.shortcode, c.value, d.long_descript, pv.code_id as country_pv from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
left join vista.tiscmcode pv on (pv.value = c.value and pv.code_id like 'Country#%')
where c.code_id like ('BSV%') and pv.code_id is null
order by c.value;
/*
CODE_ID      SHORTCODE   VALUE  LONG_DESCRIPT           COUNTRY_PV  
-----------  ----------  -----  ----------------------  ----------  
BSVLAND#208  208         208    GDR                     (null)      
BSVLAND#213  213         213    Gibraltar               (null)      
BSVLAND#220  220         220    Yugoslavia              (null)      
BSVLAND#235  235         235    USSR                    (null)      
BSVLAND#238  238         238    Czechoslovakia          (null)      
BSVLAND#249  249         249    Serbien und Montenegro  (null)      
BSVLAND#363  363         363    South Sudan             (null)      
BSVLAND#531  531         531    Vietnam                 (null)      
BSVLAND#538  538         538    Yemen                   (null)      
BSVLAND#540  540         540    Vietnam                 (null)      
BSVLAND#547  547         547    Timor-Leste             (null)      
BSVLAND#732  732         732    Western Sahara          (null)      
*/


-- SIT420 (TG)
select * from vista.aurupiregister where new_nnss='7562457842433' and actualitycd=1;
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME         GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  -----------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
4611686018441401134  7562457842433    7562457842433  1         1            MOSER,NADIA  2         14071985  100            950000    (null)     2              (null)             18102018           2018-11-02     2018-11-07 15:16:06  
*/
--> CIVILSTATUSCD = 2 (L)
select kpvpartid, name, firstname, birthdate, ccivilstatus, civilstatussince, csex, deathdate, ccitizenship, validfrom, validto from vista.tpvpartner where personid='7562457842433';
/*
KPVPARTID  NAME     FIRSTNAME  BIRTHDATE   CCIVILSTATUS  CIVILSTATUSSINCE  CSEX   DEATHDATE  CCITIZENSHIP  VALIDFROM   VALIDTO     
---------  -------  ---------  ----------  ------------  ----------------  -----  ---------  ------------  ----------  ----------  
4378201    Bischof  Nadia      1985-07-14  Civil stat#L  (null)            Sex#W  (null)     (null)        1998-01-01  9999-12-31  
*/
-- Civil stat#L
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Civil stat%'
order by c.value;
-- Differenz: Nationalitycd 100 <--> ccitizenship = NULL

-- Bei den UPI-Daten muss immer der neuste Stand angezeigt werden.
select * from vista.aurupiregister where new_nnss='7564457839093' or old_ahv_or_nnss='7564457839093';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
654827912         7564457839093    7562446730345  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-11-07 14:36:08  
*/
--> New NNSS = 7562446730345
/*
CODE_ID         SHORTCODE   VALUE  LONG_DESCRIPT                                                        
--------------  ----------  -----  -------------------------------------------------------------------  
Civil stat#U    U                  Unbekannt                                                            
Civil stat#L    L           1      Ledig                                                                
Civil stat#H    H           2      Verheiratet                                                          
Civil stat#W    W           3      Verwitwet                                                            
Civil stat#S    S           4      Geschieden                                                           
Civil stat#G    G           5      Gerichtlich getrennt                                                 
Civil stat#GPS  GPS         6      Eingetragene Partnerschaft gleichgeschlechtlicher Partner            
Civil stat#GGP  GGP         7      Gerichtlich aufgelÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶ste Partnerschaft gleichgeschlechtlicher Partner  
Civil stat#GTP  GTP         8      Durch Tod aufgelÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶ste Partnerschaft gleichgeschlechtlicher Partner    
Civil stat#GRP  GRP         9      Richterlich getrennte Partnerschaft gleichgeschlechtlicher Partner   
*/
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'PVCONST%'
order by c.shortcode; -- PVCONST_59 = BDUNPS: Konfiguration fÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼r UPI-Abgleich (Zeichen im String = Vergleich/Notifikation an): C = civilstate (Zivilstand), B = birthdate (Geb.-Dat.), D = notify deathdate (notifiziere Todesdatum), U = update deathdate (Update Todesdatum), N = nationality (NationalitÃƒÆ’Ã‚Â¼t), P = PersonId (NNSS), S = Sex (Geschlecht)
--order by c.value, c.shortcode;

-- DurchfÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼hrungsstellen DFS
select distinct clegaltype from vista.tpvpartner; -- where clegaltype like '%DFS';
select p.kpvpartid, p.name, p.additionalname, r.croletype from vista.tpvrole r
left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid)
where r.croletype='Rolle#DFS' and p.validto > current date;

-- UPI-Mumie - PostkÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¶rbe
select * from vista.teimessagereference where templateid='IG_PV_URCN_V' and date(lastupdated) >= current date - 3 days order by lastupdated desc; -- SO: 90 -- Freitag: 152

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 3 days and f.HDR_IDE like 'IG_PV_URCN_V'
order by f.CREATETIME desc; -- Freitag: 109
/*
REC_IDE              HDR_IDE       PROD_STATE  CREATETIME           DESCRIPTION   
-------------------  ------------  ----------  -------------------  ------------  
1831820360006865704  IG_PV_URCN_V  S           2018-11-14 20:36:05  IG_PV_URCN_V  
1831820360006865535  IG_PV_URCN_V  S           2018-11-14 20:36:05  IG_PV_URCN_V  
(...) 
1831720490006862527  IG_PV_URCN_V  F           2018-11-13 20:49:01  IG_PV_URCN_V  
1831720490006862525  IG_PV_URCN_V  F           2018-11-13 20:49:00  IG_PV_URCN_V  
1831720490006862428  IG_PV_URCN_V  F           2018-11-13 20:49:00  IG_PV_URCN_V  
(...)
*/

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 4 days and f.HDR_IDE like 'IG_PV_URCN_V' and f.PROD_STATE='S'; -- Freitag: 0

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 3 days and f.HDR_IDE <> 'IG_PV_URCN_V' and f.HDR_IDE like 'IG_RE%' and f.PROD_STATE='S' order by createtime desc;

select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in ('1831720490006862527')
and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_DRUCK_DEZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_PDF_ABLAGE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID', 'IG_ARCHIVIERUNG')
with ur; -- PROD_STATE = F
/*
REC_IDE              PARMNAME               VALUE           
-------------------  ---------------------  --------------  
1831720490006862527  IG_EXPRESSDRUCK        N               
1831720490006862527  IG_PDF_ABLAGE          N               
1831720490006862527  IG_ELAR_PID            637316345       
1831720490006862527  IG_VERARBEITUNGSDATUM  20181113        
1831720490006862527  IG_DRUCK_DEZENTRAL     N               
1831720490006862527  DOPDOCSTAT             FINISHED        
1831720490006862527  DOPDOCID               IG_PV_URCN_V    
1831720490006862527  OS_PROCESSINGDATE      20181113204901  
1831720490006862527  IG_ARCHIVIERUNG        J               
1831720490006862527  IG_PDF_ABLAGE          N               
1831720490006862527  IG_EXPRESSDRUCK        N               
1831720490006862527  IG_DRUCK_DEZENTRAL     N               
1831720490006862527  DOPDOCSTAT             FINISHED        
*/
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE in ('1831820360006865704')
and var.parmname in ('DOPDOCID', 'DOPDOCSTAT', 'IG_DRUCK_DEZENTRAL', 'IG_EXPRESSDRUCK', 'OS_PROCESSINGDATE', 'IG_PDF_ABLAGE', 'IG_VERARBEITUNGSDATUM', 'IG_ELAR_PID', 'IG_ARCHIVIERUNG')
with ur; -- PROD_STATE = S
/*
REC_IDE              PARMNAME               VALUE     
-------------------  ---------------------  --------  
1831820360006865648  IG_EXPRESSDRUCK        N         
1831820360006865648  IG_DRUCK_DEZENTRAL     N         
1831820360006865648  IG_VERARBEITUNGSDATUM  20181114  
1831820360006865648  DOPDOCSTAT             RELEASED  
1831820360006865648  IG_PDF_ABLAGE          N         
1831820360006865648  IG_ELAR_PID            2386603   
*/
-- Nach zweitem Lauf: verschwunden!?!

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >= current date - 2 days and f.HDR_IDE like 'IG_PV_URCN_V'; --and f.PROD_STATE='S';

-- User Data
select * from vista.tpvemployee order by lastupdated desc; -- cjobrole = SaBeFuncti#3; section vs. division? ; cteamgroup = TeamGroup#IPV
/*
TPVEMPLID         KPVEMPLID         TPVROLEID         KPVPARTID_TUTOR  CTEAMGROUP     CJOBROLE      SHORTNAME  PHONE             FAX            EMAIL                       DEPARTMENT     DEPARTMENTCHIEF   DIVISION             DIVISIONCHIEF     SECTION     SECTIONCHIEF      TEAM             TEAMLEADER        EMPGROUP                                 GROUPLEADER       VALIDFROM   VALIDTO     LASTUPDATED          
----------------  ----------------  ----------------  ---------------  -------------  ------------  ---------  ----------------  -------------  --------------------------  -------------  ----------------  -------------------  ----------------  ----------  ----------------  ---------------  ----------------  ---------------------------------------  ----------------  ----------  ----------  -------------------  
168145444         168145445         168145442         (null)           TeamGroup#BW1  SaBeFuncti#1  glo27      Telefon           Fax            E-Mail                      Ressort        Ressortleiter     Bereich              Bereichsleiter    Abteilung   Abteilungsleiter  Team             Teamleiter        Gruppe                                   Gruppenleiter     1975-12-12  9999-12-31  2018-11-16 13:26:11  
*/
select c.code_id, c.shortcode, de.long_descript as de, fr.long_descript as fr, it.long_descript as it, en.long_descript as en from vista.tiscmcode c
left join vista.tiscmcode_descr de on (de.codetypeno = c.codetypeno and de.codeno = c.codeno and de.language=1)
left join vista.tiscmcode_descr fr on (fr.codetypeno = c.codetypeno and fr.codeno = c.codeno and fr.language=2)
left join vista.tiscmcode_descr it on (it.codetypeno = c.codetypeno and it.codeno = c.codeno and it.language=3)
left join vista.tiscmcode_descr en on (en.codetypeno = c.codetypeno and en.codeno = c.codeno and en.language=4)
where c.code_id like 'SaBeFuncti%'
order by c.shortcode;
/*
CODE_ID       SHORTCODE   DE                FR                           IT                     
------------  ----------  ----------------  ---------------------------  ---------------------  
SaBeFuncti#1  1           Sachbearbeiter    Collaborateur administratif  Incaricato             
SaBeFuncti#2  2           Abteilungsleiter  Chef de section              Capo divisione         
SaBeFuncti#3  3           Auszubildender    Apprenti                     Persona in formazione   
*/
select c.code_id, c.shortcode, de.long_descript as de, fr.long_descript as fr, it.long_descript as it  from vista.tiscmcode c 
left join vista.tiscmcode_descr de on (de.codetypeno = c.codetypeno and de.codeno = c.codeno and de.language=1)
left join vista.tiscmcode_descr fr on (fr.codetypeno = c.codetypeno and fr.codeno = c.codeno and fr.language=2)
left join vista.tiscmcode_descr it on (it.codetypeno = c.codetypeno and it.codeno = c.codeno and it.language=3)
where c.code_id like 'TeamGroup%'
order by c.shortcode;
/*
CODE_ID        SHORTCODE   DE               FR                  IT                 
-------------  ----------  ---------------  ------------------  -----------------  
TeamGroup#BW1  BW1         BeitrÃƒÆ’Ã‚Â¼ge Team 1  Cotisations team 1  Team contributi 1  
TeamGroup#BW2  BW2         BeitrÃƒÆ’Ã‚Â¼ge Team 2  Cotisations team 2  Team contributi 2  
TeamGroup#IPV  IPV         IPV              RPI                 RIP                
TeamGroup#IV1  IV1         IV Team 1        Team AI 1           Team AI 1          
TeamGroup#IV2  IV2         IV Team 2        Team AI 2           Team AI 2          
TeamGroup#IV3  IV3         IV Team 3        Team AI 3           Team AI 3          
TeamGroup#RE1  RE1         Renten Team 1    Team rentes 1       Team rendite 1     
TeamGroup#RE2  RE2         Renten Team 2    Team rentes 2       Team rendite 2     
*/

-- ZivilstÃƒÆ’Ã‚Â¼nde:
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'Civil stat#%'
order by c.value;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'CorresLang%'
order by c.value;

-- UPI-Register: StatusCD 2 / 3:
select * from vista.aurupiregister where statuscd = 2;
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1190273613        7564665737013    7564542734852  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-11-10 20:15:40  
1190272881        7564665763913    7567154114241  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-11-10 20:15:40  
*/
select * from vista.aurupiregister where statuscd = 3;
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1171380939        62756751153      0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-11-10 20:15:40  
1171381494        62757100156      0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2018-11-10 20:15:40  
*/

select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' order by lastupdated desc;
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and lastupdated >= '2018-11-19 07:00:44' and lastupdated <= '2018-11-19 07:20:44' order by lastupdated desc;
select * from vista.aaireplication;
select * from vista.tpvpartnerreplication where tpvpartrepid in (280849511, 34831894);
select * from vista.aaipartner;

select r.* from vista.tpvrole r where r.croletype='Rolle#MIT' /*and r.validto > current date*/ and exists  (
    select 1 from vista.tpvrole r2 where r2.kpvpartid = r.kpvpartid and r2.kpvroleid <> r.kpvroleid and r2.croletype='Rolle#MIT' /*and r2.validto > current date*/
);

select * from vista.tpvlog;


select * from vista.tpvaddress;

-- EL-Partners without civilstate
select count(distinct p.kpvpartid) as el_partners_without_civilstate from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid)
where p.ccivilstatus is null and r.croletype like '%#EL' and p.validto >= current date;

-- MQ-Replication: Formatted adress
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and ;

-- Defect 15240: [iFix] Endless-loop on POLG-validation for missing ZIP
select * from vista.tbdpostfilestreet;
/*
ZIP4 = 8510; -- Frauenfeld
ZIP4 = 8403; -- Winterthur
*/
select * from vista.tpvaddressbasic where zip like '8510%' and ccountry='Country#CH';
/*
TPVADBAID   KPVADBAID   STREET           STREETSX  UPPERSTREET      ZIP     CITY        CITYSX  UPPERCITY   CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------------  --------  ---------------  ------  ----------  ------  ----------  ---------  ----------  -------  ----------  ----------  -------------------  
283756      283757      ZÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼rcherstrasse   Z626      ZÃƒÆ’Ã…â€œRCHERSTRASSE   851000  Frauenfeld  F651    FRAUENFELD  Canton#TG  Country#CH  N        1900-01-01  9999-12-31  2008-06-19 09:05:58  
640266      640267      Postfach         P231      POSTFACH         851000  Frauenfeld  F651    FRAUENFELD  Canton#TG  Country#CH  Y        1900-01-01  9999-12-31  2008-06-19 09:12:33  
1085442869  1085442870  Langfeldstrasse  L521      LANGFELDSTRASSE  851000  Frauenfeld  F651    FRAUENFELD  Canton#TG  Country#CH  N        1900-01-01  9999-12-31  2016-10-19 16:26:20  
*/
select * from vista.tpvaddressbasic where zip like '8403%' and ccountry='Country#CH';
/*
TPVADBAID  KPVADBAID  STREET    STREETSX  UPPERSTREET  ZIP     CITY        CITYSX  UPPERCITY   CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  --------  --------  -----------  ------  ----------  ------  ----------  ---------  ----------  -------  ----------  ----------  -------------------  
215328     215330     (null)    (null)    (null)       840300  Winterthur  W536    WINTERTHUR  Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-06-19 09:04:39  
238872     238875     Postfach  P231      POSTFACH     840300  Winterthur  W536    WINTERTHUR  Canton#ZH  Country#CH  Y        1900-01-01  9999-12-31  2008-06-19 09:05:05  
*/

-- Test 
select * from vista.abdpostfilestreet where zip6='851000'; -- empty
select * from vista.abdpostfilezip where zip6='851000';
/*
TBDPOSTFILEZIPID  ZIP4  ZIPADDON  ZIP6    CITY                         SHORTCITY   COUNTRY  BFSNR  POLGNAME    CANTON  LASTUPDATED          
----------------  ----  --------  ------  ---------------------------  ----------  -------  -----  ----------  ------  -------------------  
13839             8510  00        851000  Frauenfeld Kant. Verwaltung  Frauenfeld  CH       4566   Frauenfeld  TG      2019-02-15 14:10:37  
*/
select * from vista.tpvaddressbasic where zip='851000';

-- 204785 - SO - Indexwerte ÃƒÆ’Ã‚Â¼ndern (NNPs ohne Adresse)
select * from vista.tiscmcode; -- where company_shortcode='PV';
select * from vista.tiscmcodetype where shortcode like 'PV00300010%';
select * from vista.tiscmcode where shortcode like 'PV00300010'; -- where company_shortcode='PV';
/*
CODETYPENO  CODENO   CODE_ID             SHORTCODE   COMPANY_SHORTCODE  XML_TAG  SORT_ID  CONST_FIELD        VALUE  VALID_FROM           VALID_TO             CUSER     CDATE                UUSER     UTST                 
----------  -------  ------------------  ----------  -----------------  -------  -------  -----------------  -----  -------------------  -------------------  --------  -------------------  --------  -------------------  
1000132     1020759  MSGTYPE#PV00300010  PV00300010  PV                 (null)   1        MSG_PV_1000300_01         1900-01-01 00:00:00  9999-12-31 23:59:59  cmmaster  2019-01-28 13:51:14  cmmaster  2019-01-28 13:51:14  
*/
select * from vista.tiscmcodetype_lang; -- where long_descript like 'Der bzw. die%'; -- empty
select * from vista.tiscmcodetype_lang where codetypeno=1000132 and codeno;
select * from vista.tiscmcode_descr where codeno=1020759;
select * from vista.tiscmcode_descr where long_descript like 'Der bzw. die%'; -- codeno: 1020504
select * from vista.tiscmcode where codeno=1020504; -- PV00400010 - MSG_PV_1000400_01
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NNP';

select * from ;
-- IBAN
select * from vista.tiscmcode where shortcode like 'Country%'; -- 1000082
select * from vista.tiscmcode where code_id like 'Country%' order by code_id; -- 1000082
-- ExtAddKey
select * from vista.tpvaddress;

-- Bank ohne Keymapping
select * from vista.tpvbankbasic where kpvbankid=277024889; -- Clearing-Nr.: 80808; Raiffeisen Schweiz (Kopfstelle), Raiffeisenplatz 900000 St. Gallen; created at: 2018-10-08 12:06:11
select * from vista.tbikeymapping2000 where vista_kpv_key=277024889; -- empty
--> Bank muss ÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼ber den Prozess "Neue Bank" prozessiert werden (Erstellung in Legacy, VerknÃƒÆ’Ã‚Â¼ÃƒÆ’Ã‚Â¼pfung im BI-Keymapping).

-- UPI
select * from vista.aurupiregister where name='BROENNIMANN,GERHARD';

-- MQ BEAN-Errors (FA-Address-Filter)
select out.LASTUPDATED, out.REASON, inb.INBOUNDMSG, out.outboundmsg
from vista.TSFMQOUTBOUND out
join vista.TSFMQINBOUND inb on inb.JMSCORRELATIONID = out.JMSCORRELATIONID
where out.REASON = 'MQOUTBREJ#BEANERROR'
and date(out.LASTUPDATED) >= '2019-04-13'
with ur; 

-- IK employer archive
select tikearcid, billnbr, adr1, adr2, uid, kpvpartner, kpvcorraddress from vista.tikemployerarchive where edv2000partnerid is null and kpvpartner is not null;
/*
TIKEARCID   BILLNBR      ADR1    ADR2    UID           KPVPARTNER  KPVCORRADDRESS  
----------  -----------  ------  ------  ------------  ----------  --------------  
1443056987  10000030     (null)  (null)  CHE199151200  1405039923  14587571        
1443055917  10000028     (null)  (null)  CHE433478787  1388035601  1388035640      
1443054534  10000024     (null)  (null)  CHE354393104  1352491230  1352491256      
1443050860  10000023     (null)  (null)  (null)        2467879     15855931        
1440414256  1279959      (null)  (null)  (null)        10255992    14141720        
*/
select * from vista.tikemployerarchive where adr1='Siemens AG' or billnbr='350900'; -- billnbr = 350900, edv2000partnerid = 1051003
select * from vista.tpvpartner where name='Siemens AG';
select * from vista.tbikeymapping2000 where edv2000_zid_key=1051003; -- kpvpartid = 9000010001200003
update vista.tikemployerarchive set adr1 = null, adr2 = null, adr3 = null, adr4 = null, edv2000partnerid = 1051003, 
    kpvpartner=9000010001200003, kpvregisteraddress=null, kpvcorrpartner = null, lastupdated = current timestamp where billnbr='350900'; -- kpvregisteraddress=9000010001200003
select * from vista.tpvaddress where kpvpartid=9000010001200003; -- 9000010001200003

select * from vista.tpvaddressbasic;

select * from vista.tpvpartnerreplication;
select * from vista.aaireplication;

-- WS-Address for NNP?
select * from vista.tpvpartner where kpvpartid=4023538876; -- Name: Athos Weine GmbH, NNPersonTy#NNP, LegalFormC#GMBH, validfrom 2019-02-25
select * from vista.tpvaddress where kpvpartid=4023538876;
/*
TPVADRSID   KPVPARTID   KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID   CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          
----------  ----------  -------------------  ---------  ----------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  
4023539081  4023538876  963169               603297     4023539082  AddressTyp#WS  (null)     (null)     AppendixPo#V  10        10             (null)  N       AddressStr#CH  (null)        2019-01-25  9999-12-31  (null)         2019-02-22 15:39:08  
*/
select * from vista.jpvaddress where kpvadrsid=4023539082;
/*
TPVADRSID   KPVPARTID   KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID   CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                OPERATION  
----------  ----------  -------------------  ---------  ----------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  -------------------  -----------  ---------------------  ---------  
4023539081  4023538876  963169               603297     4023539082  AddressTyp#WS  (null)     (null)     AppendixPo#V  10        10             (null)  N       AddressStr#CH  (null)        2019-01-25  9999-12-31  (null)         2019-02-22 15:39:08  2019-02-22 15:39:08  ZH5717       PV:PV-Dlg-301 Adresse  I          
*/

select *RoleRelati#KE from vista.tpvrolerel;


select * from vista.tpvrolerel where crelationtype='RoleRelati#KE';
select * from vista.tpvrolerel where crelationtype='RoleRelati#ZE';
select * from vista.tpvpaymentaddr where iban is not null;
select * from vista.tpvfamilyrel;
select ccountry, count(distinct kpvbankid) as cnt_banks from vista.tpvbankbasic where length(clearingnr) < 2 or length(clearingnr) > 8 group by ccountry order by count(*) desc;


select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'AddressTyp#%'
order by c.value;

--
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like ('#%')
order by c.value;

--
select count(*) from vista.tpvpartner where validfrom > current date and cpartnertype like '%#NNP'; -- ZH: 26
select count(p.*) from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid)
where p.validfrom > current date and p.cpartnertype like '%#NNP';

select distinct croletype from vista.tpvrole;

select p.kpvpartid, r.croletype from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid)
where p.validfrom > current date and p.cpartnertype like '%#NNP'
and r.croletype <> 'Rolle#STA';
; -- ZH: 26


-- IK.2019.63123 - speciality, nbrmonths
select * from vista.tikperiod where type in (2);


-- Defect 16749: [iFix] Buttons for Partnerdata via UPI fetch invalid NNSS
select turupiregisterid, old_ahv_or_nnss, new_nnss, statuscd, actualitycd, name, gendercd, birthday, nationalitycd, lastupdated
from vista.aurupiregister where old_ahv_or_nnss='7569399963639' or new_nnss='7569399963639';
select turupiregisterid, old_ahv_or_nnss, new_nnss, statuscd, actualitycd, name, gendercd, birthday, nationalitycd, lastupdated
from vista.aurupiregister where old_ahv_or_nnss='7569399963639' or new_nnss='7569399963639' or new_nnss='7561952953828';
select * from vista.aurupiregister where old_ahv_or_nnss='7569399963639' or new_nnss='7569399963639';
select * from vista.aurupiregister where old_ahv_or_nnss='7569399963639' or new_nnss='7569399963639' or new_nnss='7561952953828';

select * from vista.aurupiregister where length(trim(old_ahv_or_nnss)) = 13 and old_ahv_or_nnss <> new_nnss; -- empty auf AIT101
select * from vista.aurupiregister where length(trim(old_ahv_or_nnss)) = 13;
update 

INSERT INTO VISTA.TURUPIREGISTER (TURUPIREGISTERID, OLD_AHV_OR_NNSS, NEW_NNSS, STATUSCD, ACTUALITYCD, NAME, GENDERCD, BIRTHDAY, NATIONALITYCD, ORIGINCD, DEATHDATE, CIVILSTATUSCD, RELCANCELLATIONCD, CIVILSTATUSCHANGE, DELIVERY_DATE, LASTUPDATED) VALUES (1339028759, '7561952953828', '7561952953828', '0', '1', 'ABDOULLOEVA,ROUCHANIA ROXANE', '2', '17081976', '212', '955000', null, null, null, null, null, '2019-05-11 20:15:38');
INSERT INTO VISTA.TURUPIREGISTER (TURUPIREGISTERID, OLD_AHV_OR_NNSS, NEW_NNSS, STATUSCD, ACTUALITYCD, NAME, GENDERCD, BIRTHDAY, NATIONALITYCD, ORIGINCD, DEATHDATE, CIVILSTATUSCD, RELCANCELLATIONCD, CIVILSTATUSCHANGE, DELIVERY_DATE, LASTUPDATED) VALUES (1339028760, '7561952953828', '7561952953828', '0', '0', 'ABDOULLOEVA TRUFFERT,ROUCHANIA ROXANE', '2', '17081976', '212', '955000', null, null, null, null, null, '2019-05-11 20:15:38');
INSERT INTO VISTA.TURUPIREGISTER (TURUPIREGISTERID, OLD_AHV_OR_NNSS, NEW_NNSS, STATUSCD, ACTUALITYCD, NAME, GENDERCD, BIRTHDAY, NATIONALITYCD, ORIGINCD, DEATHDATE, CIVILSTATUSCD, RELCANCELLATIONCD, CIVILSTATUSCHANGE, DELIVERY_DATE, LASTUPDATED) VALUES (1362964159, '7569399963639', '7561952953828', '2', '0', ',', '0', '01011800', '0  ', null, null, null, null, null, null, '2019-05-11 20:15:38');
INSERT INTO VISTA.TURUPIREGISTER (TURUPIREGISTERID, OLD_AHV_OR_NNSS, NEW_NNSS, STATUSCD, ACTUALITYCD, NAME, GENDERCD, BIRTHDAY, NATIONALITYCD, ORIGINCD, DEATHDATE, CIVILSTATUSCD, RELCANCELLATIONCD, CIVILSTATUSCHANGE, DELIVERY_DATE, LASTUPDATED) VALUES (1362964160, '7569399963639', '7561952953828', '0', '0', 'TRUFFERT,ROXANE', '2', '17081976', '212', '14000', null, null, null, null, null, '2019-05-11 20:15:38');


-- Kosovo-IBAN
select * from vista.tpvpaymentaddr where iban like 'XK%'; -- 0
select * from vista.tpvpaymentaddr where iban like 'XZ%'; -- 0
select * from vista.tpvbankbasic where ccountry like '%#XZ'; -- 0
select * from vista.tpvbankbasic where ccountry like '%#XK'; -- 0
select * from vista.tpvaddressbasic where ccountry like '%#XZ'; -- 58
select * from vista.tpvaddressbasic where ccountry like '%#XK'; -- 0
select count(distinct kpvpartid) as cnt_xz from vista.tpvpartner where ccitizenship like '%#XZ' or ccountryofliving like '%#XZ'; -- 302

select * from vista.tpvpartner;


-- 206020 - SG - Studenten
select * from vista.tikemployerarchive where billnbr='10010889'; -- ERFASSTCOD#MGPBNESTUD
select count(*) from vista.tikemployerarchive where cregistercode='ERFASSTCOD#MGPBNESTUD' and validto >= current date; -- 13'003 / 0
select count(*) from vista.tikemployerarchive where cregistercode='ERFASSTCOD#MGPBNESTUD' and validto >= current date; -- 66'425 / 0
select count(*) from vista.tikemployerarchive where cregistercode='ERFASSTCOD#MGPBNESTUD' and validto = '2018-12-31'; -- 104 (SG) / 99 (ZH)
select count(*) from vista.tikemployerarchive where cregistercode='ERFASSTCOD#MGPBNESTUD' and validto = '2017-12-31'; -- 1979 (SG) / 10032 (ZH)


--
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003'; -- and outboundmsg like '%personid%' fetch first 10 rows only; -- 0
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and outboundmsg like '%PARTNER%';
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and outboundmsg like '%LI.PERSONID%';

--
select * from vista.tpvpartner where kpvpartid=167913487;


-- Create Minipartner Retry
select distinct jmstype from vista.tsfmqinbound; -- LZ.PV-I001
select * from vista.tsfmqinbound where jmstype='LZ.PV-I002' and reason is not null; 

-- 
select * from vista.tikheader where vnr='7562402397001'; ---554434228
select * from vista.tikaccount where tikheadid=554434228; --563409759
select * from vista.tikbooking where tikacctid=563409759;

--
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and outboundmsg like '%foreignZipCode%';

-- IK.2019.63884 (Optimierung LZ.IK-RR001 fÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã‚Â¦ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¼r grosse Mengen)
-- Message-ID: 414d5120414258325a485020202020208a67be5c2633e67c
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001';
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001'; 
select * from vista.tsfmqinbound where jmsmessageid='ID:414d5120414258325a485020202020208a67be5c2633e67c'; -- JMSCORRELATIONID = 'c4662663-25bc-41fe-9190-0f38c922cccd';
select * from vista.tsfmqoutbound where jmsmessageid='ID:414d5120414258325a485020202020208a67be5c2633e67c'; -- empty
select * from vista.tsfmqoutbound where jmscorrelationid='c4662663-25bc-41fe-9190-0f38c922cccd';
-- Abr.-Nr. = L96145
select * from vista.tikbooking where billnbr='L96145';
select count(*) from vista.tikbooking where billnbr='L96145'; -- 1238562
select * from vista.tikperiod where tikbopeid in (select tikbopeid from vista.tikbooking where billnbr='L96145');

select count(*) from (
select b.tikbookid, b.tikacctid, b.billnbr, b.bookingdate, b.income, b.clastaction,
p.begindate, p.enddate, p.refyear
from vista.tikbooking b
join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
where b.billnbr='L96145' and b.clastaction <> 'IKBUCHHIST#d' and (
    ( year(p.begindate) >= 2017 and year(p.enddate) <= 2017 ) or
    ( p.refyear >= 2017 and p.refyear <= 2017)
)
); -- ZH: 46236

with x as (
select b.tikbookid, b.tikacctid, b.billnbr, b.bookingdate, b.income, b.clastaction,
p.begindate, p.enddate, p.refyear
from vista.tikbooking b
join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
where b.billnbr='L96145' and b.clastaction <> 'IKBUCHHIST#d' and (
    ( year(p.begindate) >= 2017 and year(p.enddate) <= 2017 ) or
    ( p.refyear >= 2017 and p.refyear <= 2017)
) fetch first 50000 rows only
) select * from vista.tikbooking b where b.tikbookid in (select x.tikbookid from x);


select b.*
from vista.tikbooking b
join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
where b.billnbr='L96145' and b.clastaction <> 'IKBUCHHIST#d' and (
    ( year(p.begindate) >= 2018 and year(p.enddate) <= 2018 ) or
    ( p.refyear >= 2018 and p.refyear <= 2018)
);

-- AIT101
call MIGRATION.PIK_GENERATE_TESTDATA_BOOKINGS('L96145', 10000, '2018', 25000); -- 30'000 @ 10 sec.

select * from vista.tikbooking order by lastupdated desc;
select * from vista.tikbooking where bookedby='XXIK01';
select * from vista.tsfmqinbound order by lastupdated desc;
select * from vista.tsfmqoutbound order by lastupdated desc;

select (max(outb.lastupdated) - max(inb.lastupdated)) / 60 as runtime_minutes from vista.tsfmqoutbound outb, vista.tsfmqinbound inb; -- 10'000 = 3.74 minutes

select * from vista.tikperiod where tikbopeid in (
    select tikbopeid from vista.tikbooking where bookedby='XXIK01'
);

select * from vista.tikbooking where bookedby='XXIK01';

-- Clean-Up
delete from vista.tikbooking where bookedby='XXIK01';
delete from vista.tikperiod where begindate='2018-01-01' and lastupdated >= '2019-05-28';
delete from vista.tsfmqinbound;
delete from vista.tsfmqoutbound;

select * from vista.tikemployerarchive where upper(adr1) like 'SCHUPPI%';

select b.tikbookid, b.tikacctid, b.billnbr, b.bookingdate, b.income, b.clastaction,
p.begindate, p.enddate, p.refyear
from vista.tikbooking b
join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
where  b.clastaction <> 'IKBUCHHIST#d' --and (
 --   ( year(p.begindate) >= 2017 and year(p.enddate) <= 2017 ) or
 --   ( p.refyear >= 2017 and p.refyear <= 2017)
--) fetch first 50000 rows only
and b.billnbr = 'L96145' order by b.lastupdated desc
;

-- Ticket ?
SELECT * FROM vista.tpvpartner WHERE kpvpartid=952256; --POLG , kpvpartid_ahvbranchnr = 29651346
SELECT * FROM vista.jpvpartner WHERE kpvpartid=952256; -- kpvpartid_ahvbranchnr: immer gesetzt

SELECT * FROM vista.tpvpartner WHERE CLEGALTYPE='NNPersonTy#POLG' AND CCANTON='Canton#ZG' AND validto='9999-12-31';

SELECT * FROM vista.tpvpartner WHERE kpvpartid=29651346; ---AHVZ

SELECT * FROM vista.tpvpartner WHERE clegaltype='NNPersonTy#AHVZ' AND validto='9999-12-31';

SELECT * FROM vista.jpvaddress WHERE kpvpartid=29651346; --AHVZ
SELECT * FROM vista.tpvaddress WHERE kpvpartid=952256; --POLG

SELECT * FROM vista.tsfmqoutbound WHERE outboundmsg LIKE '%compFundBranchLinkHist%' AND lastupdated >'2019-05-26'; 
SELECT * FROM vista.tsfmqoutbound WHERE outboundmsg LIKE '%<ns3:triggeringObjectKey>952256</ns3:triggeringObjectKey>%' AND lastupdated >'2019-05-26';

-- Defect IBAN LI not shown on family payment address GUI
select * from vista.tpvpaymentaddr where iban like 'DE%';

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'NoFiGen#%'
order by c.shortcode;

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('BusinessAp#RE', 'BusinessAp#HE', 'BusinessAp#EL', 'BusinessAp#IK') or c.code_id like 'NoFiLog#%' or c.code_id like 'NoFiGen#%'
order by c.code_id, c.shortcode;

select * from vista.tpvpaymentaddr;
select * from vista.tpvrolerel;
select cspecialcode, count(*) from vista.tikemployerarchive group by cspecialcode;
select cmembertype, count(*) from vista.tikemployerarchive group by cmembertype;
select * from vista.tikemployerarchive where cspecialcode is not null;

select * from vista.tpvpaymentaddr where iban is not null;

select ccivilstatus, cseparation from vista.tpvpartner where ccivilstatus='Civil stat#S';

select * from vista.tpvrolerel where crelationtype='RoleRelati#GV' and kpvpartid_addressee2 is not null; -- empty (SG / ZH)

-- ZIP not in Postfile
select * from vista.abdpostfilestreet where country='CH' and zip6='123456';
select * from vista.abdpostfilezip where country='CH' and zip6='123456';

select * from vista.tsfmqinbound; --SGCS0A01
select distinct username from vista.tsfmqinbound where reason is null;
select distinct username from vista.tsfmqoutbound where reason is null;

-- 209191 - prodFR: B&Z COT - Gemeinde PV
select p.* -- p.KPVPARTID, p.NAME, p.ccanton, P.CLEGALTYPE, P.VALIDTO
from vista.TPVPARTNER p
left outer join vista.TPVREGIONMUNAUTH reg on reg.KPVPARTID = p.KPVPARTID
where reg.KPVREGMUNAUTHID is null
and p.CLEGALTYPE like '%POLG';

select p.* -- p.KPVPARTID, p.NAME, p.ccanton, P.CLEGALTYPE, P.VALIDTO
from vista.TPVPARTNER p
left outer join vista.TPVREGIONMUNAUTH reg on reg.KPVPARTID = p.KPVPARTID
where reg.KPVREGMUNAUTHID is not null
and p.CLEGALTYPE like '%POLG';

select * from vista.tpvregionmunauth;

select p.kpvpartid
from vista.TPVPARTNER p
left outer join vista.TPVREGIONMUNAUTH reg on reg.KPVPARTID = p.KPVPARTID
where reg.KPVREGMUNAUTHID is null
and p.CLEGALTYPE like '%POLG';

update vista.tpvpartner set clegaltype='NNPersonTy#POLG_xxx', lastupdated=current timestamp where clegaltype='NNPersonTy#POLG';
update vista.tpvpartner set clegaltype='NNPersonTy#POLG', lastupdated=current timestamp where clegaltype='NNPersonTy#POLG_xxx';
delete from vista.tpvregionmunauth;

-- 209191 - FR - Wrong formatted address
select p.KPVPARTID, p.TPVPARTID, p.NAME, p.VALIDFROM as p_validfrom, p.VALIDTO as p_validto, p.LASTUPDATED,
adr.KPVADRSID, adr.TPVADRSID, adr.CADDRESSTYPE, adr.VALIDFROM as a_validfrom, adr.VALIDTO as a_validto, adrb.STREET, adrb.CITY
from vista.TPVPARTNER p
join vista.TPVADDRESS adr on adr.KPVPARTID = p.KPVPARTID
join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.KPVPARTID = 958742;
/*
KPVPARTID  TPVPARTID  NAME                   P_VALIDFROM  P_VALIDTO   LASTUPDATED          KPVADRSID  TPVADRSID  CADDRESSTYPE   A_VALIDFROM  A_VALIDTO   STREET            CITY    
---------  ---------  ---------------------  -----------  ----------  -------------------  ---------  ---------  -------------  -----------  ----------  ----------------  ------  
958742     958740     Commune du Bas-Vully   1900-01-01   2015-12-31  2015-10-19 16:41:07  4605971    4605969    AddressTyp#GS  1900-01-01   2003-11-24  Nant              Sugiez  
958742     456658711  Commune de Mont-Vully  2016-01-01   9999-12-31  2015-10-19 16:41:07  4605971    4605969    AddressTyp#GS  1900-01-01   2003-11-24  Nant              Sugiez  
958742     958740     Commune du Bas-Vully   1900-01-01   2015-12-31  2015-10-19 16:41:07  4605971    4605991    AddressTyp#GS  2003-11-25   9999-12-31  Route Principale  Sugiez  
958742     456658711  Commune de Mont-Vully  2016-01-01   9999-12-31  2015-10-19 16:41:07  4605971    4605991    AddressTyp#GS  2003-11-25   9999-12-31  Route Principale  Sugiez  
*/
-- Repli-Test
-- Test_BZ.PV-I003_specific_replication.cmd
-- AIT101 = IBM_TSS_TSS1501A.txt
select * from vista.tsfmqinbound;
select * from vista.tsfmqoutbound order by lastupdated desc;

-- 207561 - ZG - CompfundbranchLinkHist
select * from vista.tpvpartner where kpvpartid=952256; -- kpvpartid_ahvbranchnr = 29651346
select * from vista.tsfmqoutbound where outboundmsg like '%<ns2:lzPartnerKey>952256</ns2:lzPartnerKey>%';
select * from vista.tpvpartner where kpvpartid=952256;
/*
delete from vista.tpvaddress where kpvpartid=29651346;
delete from vista.kpvaddress where kpvadrsid in (2986571, 29651427);
delete from vista.tpvpartner where kpvpartid=29651346;
delete from vista.kpvpartner where kpvpartid=29651346;
delete from vista.tpvpartner where kpvpartid=952256;
delete from vista.tpvaddress where kpvpartid=952256;
select * from vista.tpvaddress order by lastupdated desc;
delete from vista.tpvaddressbasic where kpvadbaid in (172811, 515924, 934581);
delete from vista.kpvaddressbasic where kpvadbaid in (172811, 515924, 934581);
delete from vista.tsfmqinbound;
delete from vista.tsfmqoutbound;
*/


-- 209685 - ZG - Liste aller Buchungen
select * from vista.tikbooking where billnbr='116913' and year(bookingdate)=2017;
select * from vista.tikbookingdelivered where billnbr='116913';

-- 209897 - FR - Formatted Address falsch in XML (ville de Fribourg)
select * from vista.tpvpartner where name='Ville de Fribourg'; -- POLG: 958035 (andere: NNPs)
select * from vista.tpvaddress where kpvpartid=958035 and appendix1='Service des relations humaines';


-- 210133 - IKACC10002 - Splitting nicht ausfÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¼hrbar
select * from vista.tiksplittingorder where vnr='92055156117';
/*
TIKSPORID   TIKSPORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE       VNR            VNRNAME             VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           VNRSPOUSE      VISTADOCREF  LASTUPDATED          
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  -------------  -------------  ------------------  -------------  ----------------  -----------  ------------------  -------------  -----------  -------------------  
1996143787  (null)             79774003   2019-05-03  SZMZR#95  17          0           0               20          0           RE SPLITT CDO  92055156117    VONEY,FRITZ MARTIN  (null)         2019-05-03        (null)       ZAS                 7564572326591  (null)       2019-05-06 20:29:04  
*/
select * from vista.tikowner where tikownrid=76498197; -- kpvroleid=70385981
select * from vista.tikheader where tikheadid=79774003 or tikownrid=76498197;
/*
TIKHEADID   TIKOWNRID  VNR            NAME                BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ---------  -------------  ------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
79774003    76498197   92055156117    VONEY,FRITZ MARTIN  1955       2           25        SEXCODEZAS#1  BSVLAND#100                 F                2010-09-22 12:57:26  
2001495742  76498197   7562335183658  VONEY,FRITZ MARTIN  1955       2           25        SEXCODEZAS#1  BSVLAND#100  92055156117    F                2019-05-08 22:12:57  
*/
select * from vista.tikaccount where tikheadid in (79774003, 2001495742);
/*
TIKACCTID   TIKHEADID   CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE           CSTATE      CZIKREASON  ZIKAK   ZIKBO   ZIKCLOSINGDATE  LASTUPDATED          
----------  ----------  ------------  ------------  ---------------  -----------------  ----------  ----------  ------  ------  --------------  -------------------  
82673672    79774003    ACCTYPE#IK    1973          (null)                              IKSTATUS#O  (null)      (null)  (null)  (null)          2010-09-22 13:39:15  
2003268367  2001495742  ACCTYPE#IK    2019          SZMZR#61         AUT. IKEROEFFNUNG  IKSTATUS#O  SZMZR#95    20      0       2019-05-03      2019-05-08 22:12:57  
*/
select b.tikbookid, b.billnbr, b.income, b.ccontributiontype, b.lastupdated, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, 
ea.billnbr, ea.validfrom as ea_validfrom, ea.validto as ea_validto, ea.edv2000partnerid, ea.kpvpartner, partner.kpvpartid, partner.name, partner.validfrom as p_validfrom, partner.validto as p_validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
left join vista.tpvpartner partner on (partner.kpvpartid = ea.kpvpartner)
where b.tikacctid=82673672; -- a few missing pv-Links:

select b.tikbookid, b.billnbr, b.ccontributiontype, b.lastupdated, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, 
ea.billnbr, ea.validfrom as ea_validfrom, ea.validto as ea_validto, ea.edv2000partnerid, ea.kpvpartner, partner.kpvpartid, partner.name, partner.validfrom as p_validfrom, partner.validto as p_validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
left join vista.tpvpartner partner on (partner.kpvpartid = ea.kpvpartner)
where b.tikacctid=82673672 and ea.kpvpartner is null;
/*
TIKBOOKID  BILLNBR      CCONTRIBUTIONTYPE  LASTUPDATED          TIKBOPEID  REFYEAR  BEGINDATE   ENDDATE     CSPECIALITY    TYPE  BILLNBR      EA_VALIDFROM  EA_VALIDTO  EDV2000PARTNERID  KPVPARTNER  KPVPARTID  NAME    P_VALIDFROM  P_VALIDTO  
---------  -----------  -----------------  -------------------  ---------  -------  ----------  ----------  -------------  ----  -----------  ------------  ----------  ----------------  ----------  ---------  ------  -----------  ---------  
97251079   10010057266  SZBEITRART#1       2010-09-22 16:45:26  97251080   1973     (null)      (null)      IKBEITRBES#00  3     10010057266  1968-01-01    1980-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251110   10010057266  SZBEITRART#1       2010-09-22 16:45:26  97251112   1974     (null)      (null)      IKBEITRBES#00  3     10010057266  1968-01-01    1980-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251143   10010057266  SZBEITRART#1       2010-09-22 16:45:26  97251144   1975     (null)      (null)      IKBEITRBES#00  3     10010057266  1968-01-01    1980-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251205   10010057266  SZBEITRART#1       2010-09-22 16:45:26  97251206   1976     (null)      (null)      IKBEITRBES#00  3     10010057266  1968-01-01    1980-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251261   10010039603  SZBEITRART#1       2010-09-22 16:45:26  97251262   1977     (null)      (null)      IKBEITRBES#00  3     10010039603  1948-01-01    9999-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251295   10010039603  SZBEITRART#1       2010-09-22 16:45:26  97251296   1978     (null)      (null)      IKBEITRBES#00  3     10010039603  1948-01-01    9999-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251321   10010054666  SZBEITRART#1       2010-09-22 16:45:26  97251322   1978     (null)      (null)      IKBEITRBES#00  3     10010054666  1948-01-01    9999-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251349   10010054666  SZBEITRART#1       2010-09-22 16:45:26  97251351   (null)   1979-01-01  1979-11-30  (null)         1     10010054666  1948-01-01    9999-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
97251386   10010048325  SZBEITRART#1       2010-09-22 16:45:26  97251388   (null)   1979-11-01  1979-12-31  (null)         1     10010048325  1948-01-01    9999-12-31  (null)            (null)      (null)     (null)  (null)       (null)     
*/
select distinct (b.billnbr)
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
left join vista.tpvpartner partner on (partner.kpvpartid = ea.kpvpartner)
where b.tikacctid=82673672 and ea.kpvpartner is null;
/*
10010039603  
10010048325  
10010054666  
10010057266  
*/

select b.tikbookid, b.billnbr, b.income, b.ccontributiontype, b.lastupdated, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, ea.billnbr, ea.validfrom, ea.validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
where b.tikacctid=2003268367;
/*
TIKBOOKID   BILLNBR  INCOME   CCONTRIBUTIONTYPE  LASTUPDATED          TIKBOPEID   REFYEAR  BEGINDATE  ENDDATE  CSPECIALITY           TYPE  BILLNBR  VALIDFROM  VALIDTO  
----------  -------  -------  -----------------  -------------------  ----------  -------  ---------  -------  --------------------  ----  -------  ---------  -------  
2003268368  (null)   750.00   SZBEITRART#8       2019-05-08 22:12:57  2003268369  1997     (null)     (null)   IKBEITRBES#Splitting  3     (null)   (null)     (null)   
2003268370  (null)   2925.00  SZBEITRART#8       2019-05-08 22:12:57  2003268371  1984     (null)     (null)   IKBEITRBES#Splitting  3     (null)   (null)     (null) 
*/

select * from vista.tikheader where vnr='7564572326591'; -- empty
select * from vista.tpvpartner where personid='7564572326591'; -- 73399120
select * from vista.tpvrole where kpvpartid=73399120; -- IK: 73399144
select * from vista.tikowner where kpvroleid=73399144; -- 77374130
select * from vista.tikheader where tikownrid=77374130;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                         BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ---------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
78232513   77374130   14460580111    BAUMANN,BARBARA              1960       3           18        SEXCODEZAS#2  BSVLAND#100                 T                2010-09-22 12:40:49  
79776355   77374130   92060580318    VONEY-BAUMANN,BARBARA HELGA  1960       3           18        SEXCODEZAS#2  BSVLAND#100  14460580111    T                2010-09-22 12:57:28  
*/
select * from vista.tikaccount where tikheadid in (78232513, 79776355);
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE  CSTATE      CZIKREASON  ZIKAK   ZIKBO   ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  --------  ----------  ----------  ------  ------  --------------  -------------------  
81645956   78232513   ACCTYPE#IK    1980          SZMZR#61                   IKSTATUS#O  (null)      (null)  (null)  (null)          2010-09-22 13:21:59  
82675196   79776355   ACCTYPE#IK    1983          SZMZR#25         ZW 73     IKSTATUS#O  (null)      (null)  (null)  (null)          2010-09-22 13:39:16  
*/
select b.tikbookid, b.billnbr, b.income, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, ea.billnbr, ea.validfrom, ea.validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
where b.tikacctid=81645956; -- ok

select b.tikbookid, b.billnbr, b.income, b.ccontributiontype, b.lastupdated, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, ea.billnbr, ea.validfrom, ea.validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
where b.tikacctid=82675196;
/*
TIKBOOKID   BILLNBR      INCOME    CCONTRIBUTIONTYPE  LASTUPDATED          TIKBOPEID   REFYEAR  BEGINDATE   ENDDATE     CSPECIALITY           TYPE  BILLNBR  VALIDFROM   VALIDTO     
----------  -----------  --------  -----------------  -------------------  ----------  -------  ----------  ----------  --------------------  ----  -------  ----------  ----------  
97113105    303164       10725.00  SZBEITRART#1       2010-09-22 16:43:47  97113106    (null)   1983-08-01  1983-12-31  (null)                1     303164   1974-01-01  1993-05-31  
97113133    303164       5850.00   SZBEITRART#1       2010-09-22 16:43:47  97113135    (null)   1984-01-01  1984-03-31  (null)                1     303164   1974-01-01  1993-05-31  
101574281   D66251       150.00    SZBEITRART#1       2010-09-22 17:39:58  101574284   (null)   2006-09-01  2006-09-30  (null)                1     D66251   2000-05-01  9999-12-31  
103940331   546325       1500.00   SZBEITRART#1       2010-09-22 18:11:36  103940332   (null)   1997-08-01  1997-08-31  (null)                1     546325   1984-12-01  2008-07-31  
2001497319  (null)       -750.00   SZBEITRART#8       2019-05-07 21:02:45  2001497320  1997     (null)      (null)      IKBEITRBES#Splitting  3     (null)   (null)      (null)      
2001497347  (null)       -2925.00  SZBEITRART#8       2019-05-07 21:02:45  2001497348  1984     (null)      (null)      IKBEITRBES#Splitting  3     (null)   (null)      (null)      
*/
select count(*) from vista.tikbooking where billnbr is null; -- 727065
select * from vista.aurupiregister where old_ahv_or_nnss in ('7562335183658', '92055156117', '7564572326591', '14460580111', '92060580318');

select b.tikbookid, b.billnbr, b.income, p.tikbopeid, p.refyear, p.begindate, p.enddate, p.cspeciality, p.type, ea.billnbr, ea.validfrom, ea.validto
from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikemployerarchive ea on (ea.billnbr = b.billnbr)
where b.tikacctid in (81645956); -- ok

-- Spouse:
select * from vista.tikheader where vnr='7564572326591'; -- empty
select * from vista.tikheader where vnr='92060580318';

-- PVJNOTIF - CleanUp - 09.07.2019
select * from vista.tpvnotification; -- NotiState#NEW
select * from vista.tpvnotification where cstate='NotiState#ERROR';
select * from vista.tpvlog;
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('Rolle#IP', 'Rolle#IPV', 'Rolle#VB')
order by c.value;

select 
select count(*) as cnt_log from vista.tpvlog; -- 197408
select count(*) as cnt_log from vista.tpvlog where logtime < current date - 1 month;

-- HÃƒÂ¤ufigste Strassennamen
select * from vista.tbdpostfilestreet;
with str as (
    select distinct street, zip4 from vista.tbdpostfilestreet 
)
select str.street, count(*) as cnt_street
from str
group by str.street
order by count(*) desc;


select * from vista.tiscmcode_descr where codetypeno=1000132 and codeno=1020759 and language=4;
select code.shortcode, lang.long_descript from vista.tiscmcode code
left join vista.tiscmcode_descr lang on (lang.codetypeno = code.codetypeno and lang.codeno = code.codeno and language = 4)
where code.shortcode='PV00820180';

-- VB-Rollen
select distinct croletype, count(*) cnt_roles from vista.tpvrole
group by croletype;
update vista.tpvrole set croletype='Rolle#VB', lastupdated=current timestamp where croletype='Rolle#AB'; -- 145
update vista.tpvpartner set cpartnertype='PartnerTyp#NP', lastupdated = current timestamp where kpvpartid in (select kpvpartid from vista.tpvrole where croletype='Rolle#VB'); -- 151
select * from vista.tpvpartner where kpvpartid=168182706;
select * from vista.tpvrole where kpvpartid=168182706;

-- IG_PV_URCN_V
select old_ahv_or_nnss, new_nnss, statuscd, actualitycd, name, delivery_date from vista.aurupiregister where delivery_date is not null and actualitycd = 1;

select old_ahv_or_nnss, new_nnss, statuscd, actualitycd, name, delivery_date 
from vista.aurupiregister where delivery_date is not null and statuscd = 2;
/*
OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  DELIVERY_DATE  
---------------  -------------  --------  -----------  ----  -------------  
7562108891704    7565784585974  2         0            ,     2019-07-04     
7562147345268    7561021934031  2         0            ,     2019-07-04     
*/
select old_ahv_or_nnss, new_nnss, statuscd, actualitycd, name, delivery_date 
from vista.aurupiregister where delivery_date is not null and statuscd = 3;
/*
OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  DELIVERY_DATE  
---------------  -------------  --------  -----------  ----  -------------  
7562001340347    0              3         0            ,     2019-06-27     
7565197220127    0              3         0            ,     2019-06-13 
*/

-- SEDEX
select * from vista.TZAXMLSDXRECORD;

-- PV.2019.64454 - Studyapp - Sprache bei createMiniPartner
select * from vista.tsfmqoutbound where jmstype='LZ.PV-RR001' order by lastupdated desc fetch first 100 rows only;
select * from vista.tsfmqinbound; -- where jmstype='LZ.PV-RR001' order by lastupdated desc fetch first 100 rows only;

select * from vista.tikbookingdelivered;

-- 210731 - TG - UTF-8 XML
select * from vista.tpvpartner where kpvpartid=359617995;
select * from vista.tpvpartner where name='MÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼ller';

select * from vista.tpvpartner where kpvpartid=956470;
select * from vista.abdpostfilestreet;

-- DOPIX
select * from vista.tikreminder where vistadocref is not null;
select * from vista.tikinsurancerequest where vistadocref is not null;

-- default values
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NP' and upper(name) like ('DUM%');
select * from vista.tpvemployee;

-- iFix Kandidat (autosend)
-- 7563715325132 -- SIT401
select h.*, zo.*, coll.* from vista.tikzikorder zo 
left join vista.tikcollection coll on (coll.vnr = zo.vnr)
left join vista.tikheader h on (h.vnr = zo.vnr)
where zo.csz = 'SZMZR#71' and coll.vnr is not null and length(zo.vnr) = 13;
-- 84662386110  

-- RfS 207322 - PVJNOTIF
select c.code_id, c.shortcode, c.codetypeno, c.codeno, c.const_field, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id  like 'BusinessAp#%'
order by c.value;
/*
CODE_ID         SHORTCODE   CODETYPENO  CODENO    CONST_FIELD               VALUE             LONG_DESCRIPT                           
--------------  ----------  ----------  --------  ------------------------  ----------------  --------------------------------------               
BusinessAp#FAK  FAK         1022380     33573458  BUSINESSAPPLICATION_FAK2                                                            
BusinessAp#FZ   FZ          1022380     1022398   BUSINESSAPPLICATION_FAK                     Familienausgleichskasse                 
*/
update vista.tiscmcode c set c.const_field='BUSINESSAPPLICATION_FAK', c.uuser='TA207322', c.utst=current timestamp where c.const_field='BUSINESSAPPLICATION_FAK2' and c.code_id='BusinessAp#FAK';
update vista.tiscmcode c set c.const_field='BUSINESSAPPLICATION_FZ', c.uuser='TA207322', c.utst=current timestamp where c.const_field='BUSINESSAPPLICATION_FAK' and c.code_id='BusinessAp#FZ';

select c.code_id, c.shortcode, c.codetypeno, c.codeno, c.const_field, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id  like 'Rolle#%'
order by c.value;
/*
CODE_ID      SHORTCODE   CONST_FIELD  VALUE            LONG_DESCRIPT             
-----------  ----------  -----------  ---------------  ------------------------  
(...)               
Rolle#FAK    FAK         ROLLE_FAK    BusinessAp#FAK2  FAK-BezÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼ger               
Rolle#FAKK   FAKK        ROLLE_FAKK   BusinessAp#FAK2  FAK-Kind                  
(...)               
*/

select count(*) from vista.tpvlog; -- 564694
select count(*) from vista.tpvlog where date(lastupdated) <= (current date - 1 month); -- ZH: 395625
select count(*) from vista.tpvlog where date(lastupdated) > (current date - 1 month); -- ZH: 170226
delete from vista.tpvlog where date(lastupdated) <= (current date - 1 month);
select * from vista.tiscmcode;
-- CM:
update vista.tiscmcode c set c.value='BusinessAp#FAK', c.uuser='TA207322', c.utst=current timestamp where c.value='BusinessAp#FAK2' and c.code_id  in ('Rolle#FAK', 'Rolle#FAKK');

-- Defect 19001 - [iFix] IK.2019.65856: empty billdescr if PV Partner validFrom > booking period
select * from vista.tikheader where vnr='7567799077161';
/*
TIKHEADID   TIKOWNRID   VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
1358698532  1358698531  7567799077161  MAITA,ANTONIO  1953       7           3         SEXCODEZAS#1  BSVLAND#218  7567799077161  T                2019-07-31 13:23:19  
*/
select * from vista.tikowner where tikownrid=1358698531; -- kpvroleid=1358698529
select * from vista.tikemployerarchive where billnbr='1415983'; -- empty --> E15.983
select * from vista.tikemployerarchive where billnbr='E15983';
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                    ADR2             ADR3  ADR4             KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
----------  -------  ----------  -----------  ----------------------  ---------------  ----  ---------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
1224508948  E15983   (null)      BRANCHE#43   Twintec (Schweiz) GmbH  Pfandstrasse 13        8105 Regensdorf  1628855448      CHE101035183  ERFASSTCOD#MGAG  RECHTSFORM#H  EADMINCODE#N  (null)                (null)            (null)                (null)                    2019-01-01  9999-12-31  48141a69-977d-49e3-9b29-660170e7e48a  25424277    25424277        31596760            SONDERFALL#03  964713    MEMBERTYP#AK  2018-10-01 09:47:25  
*/

-- Messages: codetypeno=1000132;
select * from vista.tiscmcode_descr where long_descript like '%''%' and codeno=45087266;
select * from vista.tiscmcode_descr where long_descript like '%''%' and codeno in (
    select codeno from vista.tiscmcode where codetypeno=1000132 and company_shortcode in ('IK', 'PV')
);

select * from vista.tiscmcode where company_shortcode='PV' and code_id like '%PV00811596';
select * from vista.tiscmcode where codetypeno=1000132 and company_shortcode in ('IK', 'PV');

-- PV.2019.62921 - MQ - ZAS-Name_80_Zeichen_v01
select * from vista.aurupiregister where length(name) > 80;
select p.kpvpartid, upi.* from vista.aurupiregister upi
left join vista.tpvpartner p on (p.personid = upi.new_nnss)
where length(upi.name) > 80 and p.kpvpartid is not null;


-- TIKZASINCOME
select * from vista.tikzasincomereport order by transmissiondate desc;
/*
TIKINRETID  TIKZASINCR_IKZASIN  PROCESSEDYEAR  CREPORTTYPE  TRANSMISSIONDATE  INCOMETOTALUNTIL  INCOMETOTALCURRENT  LASTUPDATED          
----------  ------------------  -------------  -----------  ----------------  ----------------  ------------------  -------------------  
2153721917  2142034794          2019-11-26     ZASINCREP#1  2019-08-02        7820615099.4900   53090258.4700       2019-08-02 20:53:22  
2142034794  2130535567          2019-11-26     ZASINCREP#1  2019-07-26        7730932814.3600   89682285.1300       2019-07-26 20:38:47  
2130535567  2118976374          2019-11-26     ZASINCREP#1  2019-07-19        7645336687.2900   85596127.0700       2019-07-19 20:41:07  
2118976374  2107485102          2019-11-26     ZASINCREP#1  2019-07-12        7564291012.5400   81045674.7500       2019-07-12 22:08:31  
2107485102  2092581465          2019-11-26     ZASINCREP#1  2019-07-05        7425408253.8500   138882758.6900      2019-07-05 21:00:53  
2092581465  2080326290          2019-11-26     ZASINCREP#1  2019-06-28        7363360163.2600   62048090.5900       2019-06-28 21:03:43  
2080326290  2065178646          2019-11-26     ZASINCREP#1  2019-06-21        7246681591.0900   116678572.1700      2019-06-21 20:28:08  
2065178646  2055287651          2019-11-26     ZASINCREP#1  2019-06-14        7202706447.9100   43975143.1800       2019-06-14 21:00:17  
2055287651  2039853235          2019-11-26     ZASINCREP#1  2019-06-07        7150402086.5800   52304361.3300       2019-06-07 20:44:13  
2039853235  2030092932          2019-11-26     ZASINCREP#1  2019-05-31        7140640486.5300   9761600.0500        2019-05-31 21:00:38  
2030092932  2019769349          2019-11-26     ZASINCREP#1  2019-05-24        7103561339.3800   37079147.1500       2019-05-24 20:41:38  
2019769349  2008361297          2019-11-26     ZASINCREP#1  2019-05-17        6998534289.5500   105027049.8300      2019-05-17 20:43:53  
2008361297  1993667549          2019-11-26     ZASINCREP#1  2019-05-10        6811721148.4000   186813141.1500      2019-05-10 20:52:12  
1993667549  1976345199          2019-11-26     ZASINCREP#1  2019-05-03        6668809121.3400   142912027.0600      2019-05-03 21:06:40  
1976345199  1956296271          2019-11-26     ZASINCREP#1  2019-04-26        6470433631.0300   198375490.3100      2019-04-26 20:47:23  
1956296271  1944181572          2019-11-26     ZASINCREP#1  2019-04-12        6388694076.3600   81739554.6700       2019-04-12 20:55:56  
1944181572  1929661369          2019-11-26     ZASINCREP#1  2019-04-05        6265143887.2000   123550189.1600      2019-04-05 20:50:14  
1929661369  1917294190          2019-11-26     ZASINCREP#1  2019-03-29        6120160381.3500   144983505.8500      2019-03-29 21:15:48  
1917294190  1905557537          2019-11-26     ZASINCREP#1  2019-03-22        6039062012.8100   81098368.5400       2019-03-22 20:46:33  
1905557537  1893948205          2019-11-26     ZASINCREP#1  2019-03-15        5825360874.2000   213701138.6100      2019-03-15 20:45:52  
1893948205  1879955442          2019-11-26     ZASINCREP#1  2019-03-08        5687124170.6900   138236703.5100      2019-03-08 20:55:13  
1879955442  1866332818          2019-11-26     ZASINCREP#1  2019-03-01        5461154427.3400   225969743.3500      2019-03-01 21:11:23  
1866332818  1854769898          2019-11-26     ZASINCREP#1  2019-02-22        4606415665.9000   854738761.4400      2019-02-22 20:57:15  
1854769898  1842540467          2019-11-26     ZASINCREP#1  2019-02-15        3854009453.3400   752406212.5600      2019-02-15 21:10:41  
1842540467  1827711856          2019-11-26     ZASINCREP#1  2019-02-08        3486106938.5200   367902514.8200      2019-02-08 20:55:43  
1827711856  1814762701          2019-11-26     ZASINCREP#1  2019-02-01        2907966393.9100   578140544.6100      2019-02-01 20:58:12  
1814762701  1801953104          2019-11-26     ZASINCREP#1  2019-01-25        1952056992.8500   955909401.0600      2019-01-25 20:50:20  
1801953104  1787157226          2019-11-26     ZASINCREP#1  2019-01-18        1125725721.6700   826331271.1800      2019-01-18 20:52:50  
1787157226  1776092540          2019-11-26     ZASINCREP#1  2019-01-11        445636613.8200    680089107.8500      2019-01-11 20:50:06  
1776092540  1766558901          2019-11-26     ZASINCREP#1  2019-01-04        333673147.9200    111963465.9000      2019-01-04 20:42:24  
1766558901  1758523229          2019-11-26     ZASINCREP#1  2018-12-28        270773328.9800    62899818.9400       2018-12-28 20:44:34  
1758523229  1742571128          2019-11-26     ZASINCREP#1  2018-12-21        170231543.3800    100541785.6000      2018-12-22 00:14:42  
1742571128  1731997227          2019-11-26     ZASINCREP#1  2018-12-14        144150490.4500    26081052.9300       2018-12-14 21:01:14  
1731997227  1719987545          2019-11-26     ZASINCREP#1  2018-12-07        0.0000            144150490.4500      2018-12-07 20:41:01  
1719987545  1711054824          2018-11-26     ZASINCREP#2  2018-11-30        8730425247.4000   24668562.0100       2018-11-30 20:58:39  
1711054824  1703247508          2018-11-26     ZASINCREP#1  2018-11-23        8692475978.3800   37949269.0200       2018-11-23 20:41:17  
1703247508  1695027366          2018-11-26     ZASINCREP#1  2018-11-16        8690149027.1900   2326951.1900        2018-11-16 20:42:40  
*/

select * from VISTA.TIKCOLLECTION where VNR = '7560223144675';
--528243253
select * from vista.tikzikexecution where TIKCOLLID_ACTUAL = 528243253;
-- collection is closed because EXECUTIONDATE/TRANSMISIONDATE for all ZIKEXecution are set
select * from VISTA.TIKKOAUREQUEST where TIKZIORID = 528243253;

select * from VISTA.TIKKOAUREQUEST where TIKZIORID in (
    select tikziorid from VISTA.TIKCOLLECTION where VNR = '7560223144675' and transmissiondate='2008-07-10'
);


-- ZAS Income report
select * from vista.tikzasincomereport;

select * from vista.abdpostfilestreet where shortcity='Biel/Bienne' and street like 'Rue de %'; -- Rue de l'HÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â´pital
select * from vista.abdpostfilestreet where shortcity='Biel/Bienne' and street like 'Spital%';


-- 
select * from vista.tpvaddress;
select * from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
left join vista.tpvpaymentaddr pa on (pa.kpvpartid = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NP'
and a.caddresstype ;


select count(distinct(p.kpvpartid)) as cnt_partners from vista.tpvpartner p
where p.cpartnertype='PartnerTyp#NP' and p.validto >= current date
and exists (
    select 1 from vista.tpvaddress a where a.kpvpartid = p.kpvpartid and a.caddresstype='AddressTyp#GS' and a.validto >= current date
)
and NOT exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid = p.kpvpartid and a2.caddresstype='AddressTyp#WS' and a2.validto >= current date
)
and exists
(
    select 1 from vista.tpvpaymentaddr pa where pa.kpvpartid = p.kpvpartid and pa.validto >= current date
    and NOT exists (
        select 1 from vista.tpvrolerel rr where rr.kpvpaddid = pa.kpvpaddid and rr.validto >= current date
    )
);
-- SG: 3, ZH: 9 @ 19 sec
select count(distinct(p.kpvpartid)) as cnt_partners from vista.tpvpartner p
where p.cpartnertype='PartnerTyp#NP' and p.validto >= current date
and exists (
    select 1 from vista.tpvaddress a where a.kpvpartid = p.kpvpartid and a.caddresstype='AddressTyp#GS' and a.validto >= current date
)
and NOT exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid = p.kpvpartid and a2.caddresstype='AddressTyp#WS' and a2.validto >= current date
)
and exists
(
    select 1 from vista.tpvpaymentaddr pa where pa.kpvpartid = p.kpvpartid and pa.validto >= current date
    and exists (
        select 1 from vista.tpvrolerel rr where rr.kpvpaddid = pa.kpvpaddid and rr.validto >= current date
    )
);
-- SG: 0, ZH: 0
select count(distinct(p.kpvpartid)) as cnt_partners from vista.tpvpartner p
where p.cpartnertype='PartnerTyp#NP' and p.validto >= current date
and exists (
    select 1 from vista.tpvaddress a where a.kpvpartid = p.kpvpartid and a.caddresstype='AddressTyp#GS' and a.validto >= current date
)
and NOT exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid = p.kpvpartid and a2.caddresstype='AddressTyp#WS' and a2.validto >= current date
)
and exists
(
    select 1 from vista.tpvaddress a3 where a3.kpvpartid = p.kpvpartid and a3.validto >= current date and a3.caddresstype='AddressTyp#GS'
    and NOT exists (
        select 1 from vista.tpvrolerel rr where rr.kpvadrsid_corr = a3.kpvadrsid and rr.validto >= current date
    )
);
-- SG: 914, ZH: 7837 @ 22 sec

select count(distinct(p.kpvpartid)) as cnt_partners from vista.tpvpartner p
where p.cpartnertype='PartnerTyp#NP' and p.validto >= current date
and exists (
    select 1 from vista.tpvaddress a where a.kpvpartid = p.kpvpartid and a.caddresstype='AddressTyp#GS' and a.validto >= current date
)
and NOT exists (
    select 1 from vista.tpvaddress a2 where a2.kpvpartid = p.kpvpartid and a2.caddresstype='AddressTyp#WS' and a2.validto >= current date
)
and NOT exists
(
    select 1 from vista.tpvrolerel rr where rr.kpvadrsid_corr = a.kpvadrsid and rr.validto >= current date
);
-- SG: 918, ZH: 7855 @ 19 sec

-- MQ-User ProdZH
select distinct username from vista.tsfmqinbound;
/*
(...)
ZHAEMQ01
ZHBW0A01
ZHCS0A01
ZHEO0A01
ZHFK0A01
ZHIK0A01
ZHloeezi
zhIK0A01
zhigssc
zhigssch
zhloeasc
(...)
*/
select distinct jmstype, jmsdestination from vista.tsfmqinbound;
/*
JMSTYPE      JMSDESTINATION                                                               
-----------  ---------------------------------------------------------------------------  
BZ.BW-N001   queue:///BZBW.N001.EMPLOYERARCHIVE.NOTIFY                                    
EA-N001      queue://ABX2ZHP/EA.N001.EMPLOYER.NOTIFY                                      
LZ.IK-I001   queue:///BZBW.LZIK.I001.BOOKING.CREATE                                       
LZ.IK-RR001  queue:///BZBW.LZIK.RR001.DATA.SEARCH.REQ                                     
LZ.IK-RR001  queue://ABX2ZHP/EA.LZIK.RR001.DATA.SEARCH.REQ                                
LZ.IK-RR003  queue://ABX2ZHP/EA.LZIK.RR003.INITIALLOAD.REQ                                
LZ.PV-I001   queue:///BZBW.LZPV.I001.ROLE.UPDATE                                          
LZ.PV-I002   queue:///BZBW.LZPV.I002.MINIPARTNER.CREATE                                   
LZ.PV-RR001  queue://ABX2ZHP/EA.LZPV.RR001.PARTNERLIST.REQ                                
LZPV.RR002   queue://ABX2ZHP/EAZAP.LZPV.RR002.PVADDDATA.RETURN.REQ                        
(null)       queue:///LZPV.I500.DBRECORD.CHANGED?destDescription=pv+Replication+RequestQ  
*/
select * from vista.tsfmqinbound where username='ZHCS0A01'; -- BZ.BW-N001
select * from vista.tsfmqinbound where jmstype='LZ.PV-I002';
select * from vista.tsfmqinbound where username='BATCH';

-- Strassenverzeichnis
select * from vista.abdpostfilestreet;
select * from vista.abdpostfilestreet where lower(polgname) like '(%'; -- 0
select * from vista.abdpostfilestreet where lower(shortcity) like '(%'; -- 0
select * from vista.abdpostfilezip;
select * from vista.abdpostfilezip where lower(polgname) like '(%'; -- 0
select * from vista.abdpostfilezip where lower(shortcity) like '(%'; -- 0

select a.caddresstype, count(*) as cnt_po 
from vista.tpvaddress a left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where ab.ispobox='Y'
group by a.caddresstype;

ZHIKMQ01;

--
select * FROM vista.tikheader where vnr like '756%' order by vnr;

select * from VISTA.TSFMQINBOUND where jmsmessageid like 'ID:330e9b71-107d-44f8-b43e-8fed7199ead7' or jmscorrelationid = '330e9b71-107d-44f8-b43e-8fed7199ead7';
select * from VISTA.tsfmqoutbound where jmsmessageid like 'ID:330e9b71-107d-44f8-b43e-8fed7199ead7' or jmscorrelationid like '%330e9b71-107d-44f8-b43e-8fed7199ead7%';

select * from VISTA.TSFMQINBOUND where jmsmessageid like 'ID:330e9b71-107d-44f8-b43e-8fed7199ead7' or jmscorrelationid like '%330e9b71-107d-44f8-b43e-8fed7199ead7%'; -- 330e9b71-107d-44f8-b43e-8fed7199ead7
330e9b71-107d-44f8-b43e-8fed7199ead7;

-- iFix 3, SR49 - Repli validFrom aus ÃƒÂ¤ltester Periode - TG
/*
<eventDate>2019-09-03T16:58:52.722+02:00</eventDate>
        <tenant>TG</tenant>
*/
select tpvpartid, kpvpartid, name, additionalname, cpartnertype, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid=5261430;
/*
TPVPARTID  KPVPARTID  NAME                 ADDITIONALNAME  CPARTNERTYPE    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------------------  --------------  --------------  ----------  ----------  -------------------  
5261426    5261430    SHC Trade Tech GmbH  (null)          PartnerTyp#NNP  1998-07-01  2003-12-07  2019-09-04 15:47:49  
5261455    5261430    SHC Trade Tech GmbH  (null)          PartnerTyp#NNP  2003-12-08  2019-03-21  2019-03-22 07:22:02  
978486648  5261430    SHC FinTech GmbH     (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-09-02 16:20:01 
*/
-- How it was before:
/*
TPVPARTID  KPVPARTID  NAME                 ADDITIONALNAME  CPARTNERTYPE    VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------------------  --------------  --------------  ----------  ----------  -------------------  
5261426    5261430    SHC Trade Tech GmbH  Wellness        PartnerTyp#NNP  1998-07-01  2003-12-07  2019-09-04 15:47:49  
5261455    5261430    SHC Trade Tech GmbH  (null)          PartnerTyp#NNP  2003-12-08  2019-03-21  2019-03-22 07:22:02  
978486648  5261430    SHC FinTech GmbH     (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-09-02 16:20:01 
*/
select tpvpartid, kpvpartid, name, additionalname, cpartnertype, validfrom, validto, lastupdated, change_date from vista.jpvpartner where tpvpartid=978486648;
/*
TPVPARTID  KPVPARTID  NAME              ADDITIONALNAME  CPARTNERTYPE    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          
---------  ---------  ----------------  --------------  --------------  ----------  ----------  -------------------  -------------------  
978486648  5261430    SHC FinTech GmbH  (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-03-22 07:22:02  2019-03-22 07:22:02  
978486648  5261430    SHC FinTech GmbH  (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-03-22 07:22:02  2019-09-02 16:20:01  
*/
select tpvpartid, kpvpartid, name, additionalname, cpartnertype, validfrom, validto, lastupdated, change_date from vista.jpvpartner where tpvpartid=5261426;
/*
TPVPARTID  KPVPARTID  NAME                 ADDITIONALNAME  CPARTNERTYPE    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          
---------  ---------  -------------------  --------------  --------------  ----------  ----------  -------------------  -------------------  
5261426    5261430    SHC Trade Tech GmbH  Wellness        PartnerTyp#NNP  1998-07-06  2003-12-07  2009-08-27 04:46:49  2019-09-03 16:56:00  
5261426    5261430    SHC Trade Tech GmbH  Wellness        PartnerTyp#NNP  1998-07-01  2003-12-07  2019-09-03 16:56:00  2019-09-04 15:47:49 
*/
select tpvpartid, kpvpartid, name, additionalname, cpartnertype, validfrom, validto, lastupdated, change_date, operation, program, change_user from vista.jpvpartner where kpvpartid=5261430 and change_date <= '2019-09-03 16:58:52';
/*
TPVPARTID  KPVPARTID  NAME                 ADDITIONALNAME  CPARTNERTYPE    VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          OPERATION  PROGRAM                                  CHANGE_USER  
---------  ---------  -------------------  --------------  --------------  ----------  ----------  -------------------  -------------------  ---------  ---------------------------------------  -----------  
978486648  5261430    SHC FinTech GmbH     (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-03-22 07:22:02  2019-03-22 07:22:02  I          PV:PV-Dlg-20300 Nichtnatuerliche Person  tgmeg        
5261455    5261430    SHC Trade Tech GmbH  (null)          PartnerTyp#NNP  2003-12-08  9999-12-31  2009-08-27 04:46:49  2019-03-22 07:22:02  U          PV:PV-Dlg-20300 Nichtnatuerliche Person  tgmeg        
978486648  5261430    SHC FinTech GmbH     (null)          PartnerTyp#NNP  2019-03-22  9999-12-31  2019-03-22 07:22:02  2019-09-02 16:20:01  U          PV:PV-Dlg-20300 Nichtnatuerliche Person  tgam         
5261426    5261430    SHC Trade Tech GmbH  Wellness        PartnerTyp#NNP  1998-07-06  2003-12-07  2009-08-27 04:46:49  2019-09-03 16:56:00  U          53147390-20190903-165421 - RFS 212586    DKPROTG      
*/
select * from vista.tsfmqoutbound where outboundmsg like '%<ns2:lzPartnerKey>5261430</ns2:lzPartnerKey>%' and lastupdated > '2019-09-03 16:58:52';
-- AIT:
select * from vista.tsfmqoutbound order by lastupdated desc;
select * from vista.tsfmqinbound order by lastupdated desc;

select count(distinct p1.kpvpartid) as cnt_add from vista.tpvpartner p1, vista.tpvpartner p2
where p1.kpvpartid = p2.kpvpartid and p1.tpvpartid <> p2.tpvpartid and p1.validto >= current date and p1.additionalname is NULL and p2.additionalname is not NULL;
-- SG: 2964 / ZH: 6711 / TG: 1603

-- BIActive
select c.code_id, c.shortcode, c.const_field, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'PVCONST%'
order by c.value;

-- 211990 - FR - Versandadresse
/*
Ticket bitte IBM (Gerry BrÃƒÆ’Ã‚Â¶nnimann) zuweisen
@Gerry: der Fehler sollte mit iFix-9 (produktiviert im Juli 2019) behoben worden sein.
Beachte: die Akonto-Rechnung wurde am 06.08.2019 erstellt. An diesem Tag gab es noch eine Fachperiode mit TPVPARTID 961278 mit dem Gemeindenamen "Commune d'Estavayer-le-Lac" (GÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼ltigkeit 01.01.1900 - 31.12.2016) - sie wurde am 12.08.2019 auf "Commune d'Estavayer" korrigiert.
Bitte nochmals testen lassen.
*/
select * from vista.tpvpartner where tpvpartid=961278;
select tpvpartid, kpvpartid, name, additionalname, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid=961279;
/*
TPVPARTID  KPVPARTID  NAME                 ADDITIONALNAME  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  -------------------  --------------  ----------  ----------  -------------------  
961278     961279     Commune d'Estavayer  (null)          1900-01-01  2016-12-31  2019-08-12 13:10:01  
555169806  961279     Commune d'Estavayer  (null)          2017-01-01  9999-12-31  2016-10-05 14:40:26  
*/
select tpvpartid, kpvpartid, name, additionalname, validfrom, validto, lastupdated, change_date, operation from vista.jpvpartner where kpvpartid=961279;
/*
TPVPARTID  KPVPARTID  NAME                        ADDITIONALNAME  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          OPERATION  
---------  ---------  --------------------------  --------------  ----------  ----------  -------------------  -------------------  ---------  
961278     961279     Commune d'Estavayer-Le-Lac  (null)          1900-01-01  2016-12-31  2016-10-05 14:40:26  2019-08-12 13:10:01  U          
*/
select tpvpartid, kpvpartid, name, additionalname, validfrom, validto, lastupdated, change_date, operation from vista.JPVPARTNER_ARCHIVE_CC0520 where kpvpartid=961279;
-- JPVPARTNER_ARCHIVE_CC0525: empty
-- JPVPARTNER_ARCHIVE_CC0520_RESIDAUTHORTO: empty
-- JPVPARTNER_ARCHIVE_CC0520: empty 

select * from vista.tsfmqoutbound where outboundmsg like '%triggeringObjectKey>961279<%' and lastupdated > '2019-08-12 13:10:01' and lastupdated < '2019-08-12 13:15:01'; -- 1 result
select * from vista.tsfmqoutbound where outboundmsg like '%triggeringObjectKey>961279<%' and lastupdated > '2019-08-12 13:10:01' and lastupdated > '2019-08-12 13:15:01'; -- 1 result


select count(*) as cnt_upi from vista.turupiregister; -- AIT101: 4975

-- Roles
select distinct croletype from vista.tpvrole; -- Rolle#ST
select * from vista.tpvrole where croletype='Rolle#ST' and validto < '9999-12-31';

-- iFix zu fusionierten ZIK-AuftrÃƒÂ¤gen
select * from vista.tiksplittingorder t1, vista.tiksplittingexecution t2
where t1.tiksporid = t2.tiksporid
--and vnr = '7568341389169'
and t2.executiondate between '18.08.2019' and '30.09.2019'
and t1.tiksporid_revoked is null
and t2.baddendumsplitting = 1
and exists (select * from vista.tiksexc_tikbook t3, vista.tikbooking t4, vista.tikaccount t5, vista.tikheader t6 where t3.tiksexcid = t2.tiksexcid and t3.tikbookid = t4.tikbookid 
and t4.CCONTRIBUTIONTYPE = 'SZBEITRART#8' and t4.cstornocode = 'SZSTORNO#1' and t4.tikacctid = t5.tikacctid and t6.tikheadid = t1.tikheadid and t6.tikheadid = t5.tikheadid);
/*
TIKSPORID   TIKSPORID_REVOKED  TIKHEADID   ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE              VNR            VNRNAME                VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           VNRSPOUSE      VISTADOCREF          LASTUPDATED          TIKSEXCID   TIKSPORID   EXECUTIONDATE  EXECUTIONBY  ENTRANCEDATE  BADDENDUMSPLITTING  LASTUPDATED          
----------  -----------------  ----------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------------------  -------------  ---------------------  -------------  ----------------  -----------  ------------------  -------------  -------------------  -------------------  ----------  ----------  -------------  -----------  ------------  ------------------  -------------------  
2604745551  (null)             408307464   2017-02-10  SZMZR#95  1           0           0               70          0           22/1002/331498/IKSPL  7567854371562  LANZ,PETER             (null)         2017-02-10        (null)       ZAS                 7569205577043  (null)               2019-09-23 07:54:30  4328439159  2604745551  2019-08-19     ZH208        2019-05-16    1                   2019-08-19 14:20:26  
2295706113  (null)             406960281   2016-06-21  SZMZR#95  1           0           0               17          0           LE BIS                7562869760288  KRAMEL,FRANZ           (null)         2016-06-22        (null)       ZAS                 7564281980831  (null)               2019-09-23 07:26:58  4568663608  2295706113  2019-08-19     ZH208        2019-07-08    1                   2019-08-19 14:14:34  
4645173039  (null)             2306009178  2019-08-14  SZMZR#95  1           0           0               10          0           SPLITT-19             7563662512869  QUERIDO,CECILIA MARIA  (null)         2019-08-14        (null)       ZAS                 7562664707280  (null)               2019-09-23 07:53:19  4654704024  4645173039  2019-08-21     ZHIK0A01     2019-08-21    1                   2019-08-21 20:38:26  
3918578566  (null)             407547612   2019-01-23  SZMZR#95  1           0           0               1           0           VL2.3/LDU/23.01.2019  7564944419920  KABALAN,SOUKAINA       (null)         2019-01-23        (null)       ZAS                 7564206044280  VDR2420290037037029  2019-09-23 07:52:54  4692117199  3918578566  2019-09-06     ZHIK0A01     2019-09-06    1                   2019-09-06 20:51:35  
4511831324  (null)             406706514   2019-06-20  SZMZR#95  1           0           0               1           0           ZH1976                7562079126249  HALILI,SHABAN          (null)         2019-06-21        (null)       (null)              7564999700080  VDR7520260039203288  2019-09-23 07:44:50  4703909404  4511831324  2019-09-10     ZHIK0A01     2019-09-10    1                   2019-09-10 20:43:36  
3976226006  (null)             408536277   2019-02-08  SZMZR#95  1           0           0               1           0           VL2.1/KAS             7568628328973  LUSHI,JAHE             (null)         2019-02-08        (null)       ZAS                 7568995496046  VDR4220280037238322  2019-09-23 07:57:30  4714989178  3976226006  2019-09-17     ZHIK0A01     2019-09-17    1                   2019-09-17 20:48:42  
*/
-- executiondate auf Zikexecution und Splitting execution zurÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼cksetzen + executedby (null)
-- zikexec_lead1
select r.kpvroleid, t1.*, t2.* from vista.tiksplittingorder t1, vista.tiksplittingexecution t2
left join vista.tikheader h on (h.tikheadid = t1.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
where t1.tiksporid = t2.tiksporid
and t2.executiondate between '18.08.2019' and '30.09.2019'
and t1.tiksporid_revoked is null
and t2.baddendumsplitting = 1
and pension.kpvroleid is null; -- 89

select r.kpvroleid as kpvroleid_IK, pension.kpvroleid as kpvroleid_RE, b.*, t1.*, t2.* from vista.tiksplittingorder t1, vista.tiksplittingexecution t2
left join vista.tikheader h on (h.tikheadid = t1.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
where t1.tiksporid = t2.tiksporid
and t2.executiondate between '18.08.2019' and '30.09.2019'
and t1.tiksporid_revoked is null
and t2.baddendumsplitting = 1
and b.bpensionzik = 1
and b.bookingdate between '18.08.2019' and '30.09.2019'
and pension.kpvroleid is not null; -- ZH: 11


select distinct t1.vnr, h.name from vista.tiksplittingorder t1, vista.tiksplittingexecution t2
left join vista.tikheader h on (h.tikheadid = t1.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
where t1.tiksporid = t2.tiksporid
and t2.executiondate between '18.08.2019' and '30.09.2019'
and t1.tiksporid_revoked is null
and t2.baddendumsplitting = 1
and b.bpensionzik = 1
and b.bookingdate between '18.08.2019' and '30.09.2019'
and pension.kpvroleid is not null; -- SG: 11

select r.kpvroleid as kpvroleid_IK, pension.kpvroleid as kpvroleid_RE, acc.*, b.*, t1.*, t2.* from vista.tiksplittingorder t1, vista.tiksplittingexecution t2
left join vista.tikheader h on (h.tikheadid = t1.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
where t1.tiksporid = t2.tiksporid
and t2.executiondate between '18.08.2019' and '30.09.2019'
and t1.tiksporid_revoked is null
and t2.baddendumsplitting = 1
and b.bpensionzik = 1
and b.bookingdate between '18.08.2019' and '30.09.2019'
and pension.kpvroleid is not null; -- ZH: 11


-- Liste betroffener FÃƒÂ¤lle:
select distinct h.vnr, h.name, acc.czikreason, acc.zikclosingdate, acc.zikak, acc.zikbo, se.entrancedate, 
(select min(sp2.periodyearbegin) from vista.tiksplittingperiod sp2 where sp2.tiksporid = sp.tiksporid) as min_begin, 
(select max(sp2.periodyearend) from vista.tiksplittingperiod sp2 where sp2.tiksporid = sp.tiksporid) as max_end  
from vista.tiksplittingorder so, vista.tiksplittingexecution se
left join vista.tikheader h on (h.tikheadid = so.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
left join vista.tiksplittingperiod sp on (sp.tiksporid = so.tiksporid)
where so.tiksporid = se.tiksporid
and se.executiondate between '18.08.2019' and '30.09.2019'
and so.tiksporid_revoked is null
and se.baddendumsplitting = 1
--and b.bpensionzik = 1
and b.bookingdate between '18.08.2019' and '30.09.2019'
--and pension.kpvroleid is not null; -- ZH: 11
;

-- Korrektur (Liste): 
-- executiondate auf Zikexecution und Splitting execution zurÃƒÆ’Ã‚Â¼cksetzen + executedby (null)
select distinct h.vnr, h.name, acc.czikreason, acc.zikclosingdate, acc.zikak, acc.zikbo, se.entrancedate, 
(select min(sp2.periodyearbegin) from vista.tiksplittingperiod sp2 where sp2.tiksporid = sp.tiksporid) as min_begin, 
(select max(sp2.periodyearend) from vista.tiksplittingperiod sp2 where sp2.tiksporid = sp.tiksporid) as max_end,
se.tiksexcid, se.executiondate as se_executiondate, se.executionby as se_executionby, ze.tikzexcid, ze.executiondate as ze_executiondate, ze.executedby as ze_executedby
from vista.tiksplittingorder so, vista.tiksplittingexecution se
left join vista.tikheader h on (h.tikheadid = so.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
left join vista.tiksplittingperiod sp on (sp.tiksporid = so.tiksporid)
left join vista.tikzikexecution ze on (ze.tiksexcid_lead1 = se.tiksexcid)
where so.tiksporid = se.tiksporid
and se.executiondate > '18.08.2019'
and so.tiksporid_revoked is null
and se.baddendumsplitting = 1
--and b.bpensionzik = 1
and b.bookingdate > '18.08.2019'
--and pension.kpvroleid is not null; -- ZH: 11
;

-- 1) ZIK-Execution:
update vista.tikzikexecution update_ze set update_ze.executiondate = null, update_ze.executedby = null, update_ze.lastupdated = current timestamp
where update_ze.tikzexcid in (
    select distinct ze.tikzexcid
    from vista.tiksplittingorder so, vista.tiksplittingexecution se
    left join vista.tikheader h on (h.tikheadid = so.tikheadid)
    left join vista.tikowner o on (o.tikownrid = h.tikownrid)
    left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
    left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
    left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
    left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
    left join vista.tiksplittingperiod sp on (sp.tiksporid = so.tiksporid)
    left join vista.tikzikexecution ze on (ze.tiksexcid_lead1 = se.tiksexcid)
    where so.tiksporid = se.tiksporid
    and se.executiondate > '18.08.2019'
    and so.tiksporid_revoked is null
    and se.baddendumsplitting = 1
    --and b.bpensionzik = 1
    and b.bookingdate > '18.08.2019'
    --and pension.kpvroleid is not null; -- ZH: 11
    and acc.czikreason is null
);

-- 2) Splitting-Execution:
update vista.tiksplittingexecution update_se set update_se.executiondate = null, update_se.executionby = null, update_se.lastupdated = current timestamp
where update_se.tiksexcid in (
    select distinct se.tiksexcid
    from vista.tiksplittingorder so, vista.tiksplittingexecution se
    left join vista.tikheader h on (h.tikheadid = so.tikheadid)
    left join vista.tikowner o on (o.tikownrid = h.tikownrid)
    left join vista.tpvrole r on (r.kpvroleid = o.kpvroleid)
    left join vista.tpvrole pension on (pension.kpvpartid = r.kpvpartid and pension.croletype='Rolle#RE')
    left join vista.tikaccount acc on (acc.tikheadid = h.tikheadid)
    left join vista.tikbooking b on (b.tikacctid = acc.tikacctid)
    left join vista.tiksplittingperiod sp on (sp.tiksporid = so.tiksporid)
    left join vista.tikzikexecution ze on (ze.tiksexcid_lead1 = se.tiksexcid)
    where so.tiksporid = se.tiksporid
    and se.executiondate > '18.08.2019'
    and so.tiksporid_revoked is null
    and se.baddendumsplitting = 1
    --and b.bpensionzik = 1
    and b.bookingdate > '18.08.2019'
    --and pension.kpvroleid is not null; -- ZH: 11
    and acc.czikreason is null
);

-- 214187 - UR - MQ-Repli
select * from vista.tpvpartner where kpvpartid=1568938; -- Peter Rhyner AG in Liquidation -- 2019-09-20 10:27:48
select * from vista.tsfmqoutbound where outboundmsg like '%1568938%' and lastupdated >= '2019-09-20 10:27:48';


select * from vista.tpvpartner where name='MasterClean GmbH'; -- 321311674
select * from vista.tsfmqoutbound where outboundmsg like '%321311674%' and lastupdated >= '2019-09-20 16:00:40';

select * from vista.abdpostfilestreet;

select * from vista.tpvbankbasic where swiftnr is not null;

-- 
select * from vista.tsfmqoutbound where jmstype='BZ.BW-N001' order by lastupdated desc;
select distinct(reason) from vista.tsfmqoutbound where jmstype='BZ.BW-N001';
/*
MQOUTBREJ#BEANERROR  
MQOUTINFO#REPNOTREQ  
*/
select * from vista.tsfmqoutbound where jmstype='BZ.BW-N001' and jmsmessageid='ID:414d5120414258325a485020202020206233635d224eb66f'; -- empty
select * from vista.tsfmqinbound where jmstype='BZ.BW-N001' and jmsmessageid='ID:414d5120414258325a485020202020206233635d224eb66f'; -- jmscorrelationid = 2d7e3bfa-6eca-448b-b345-99bd65a9243a
select * from vista.tsfmqoutbound where jmstype='BZ.BW-N001' and jmscorrelationid = '2d7e3bfa-6eca-448b-b345-99bd65a9243a'; -- MQOUTBREJ#BEANERROR
select * from vista.tikemployerarchive where billnbr='99990009000'; -- empty
select * from vista.tpvpartner where kpvpartid=3378160415; -- Ausgleich summarische
select * from vista.tsfmqinbound order by lastupdated desc; -- MQINBREJ#MISMVERSON
select * from vista.tsfmqoutbound order by lastupdated desc; -- MQINBREJ#MISMVERSON
/*
TSFMQOUTBOUNDID  STATUS  REASON               EXECTIMEMDB  EXECTIMESRV  JMSMESSAGECLASS  JMSTYPE      JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                                   JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC                                        USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  OUTBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           LASTUPDATED          
---------------  ------  -------------------  -----------  -----------  ---------------  -----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  -------------------------------------------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
7037833          1       MQOUTBREJ#BEANERROR  1219         16           (null)           BZ.BW-N001   (null)           (null)         (null)       (null)                                               (null)         6428a268-34e0-4db2-9273-10236ba96fd2  (null)                                           (null)      (null)          (null)                        (null)             (null)        (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)                                (null)    (null)                                       (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2019-09-26 16:42:48  
7037808          1       MQOUTBREJ#BEANERROR  1188         32           (null)           BZ.BW-N001   (null)           (null)         (null)       (null)                                               (null)         6428a268-34e0-4db2-9273-10236ba96fd2  (null)                                           (null)      (null)          (null)                        (null)             (null)        (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)                                (null)    (null)                                       (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2019-09-26 16:42:46  
7037783          1       MQOUTBREJ#BEANERROR  1360         156          (null)           BZ.BW-N001   (null)           (null)         (null)       (null)                                               (null)         6428a268-34e0-4db2-9273-10236ba96fd2  (null)                                           (null)      (null)          (null)                        (null)             (null)        (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)                                (null)    (null)                                       (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2019-09-26 16:42:45  
*/
--IN:  ID:414d51205453533135303141202020200cdf7e5d2481f502


select p.birthdate, p.birthdateprec, count(*) from vista.tpvpartner p 
where p.birthdate is null and p.cpartnertype='PartnerTyp#NP' and p.lastupdated > '2019-01-01' and p.validto='9999-12-31' group by p.birthdate, p.birthdateprec;

select * from vista.tpvpartner p where p.birthdate is null and p.cpartnertype='PartnerTyp#NP' and lastupdated > '2019-01-01' and validto='9999-12-31';


select * from vista.tikemployerarchive;
select p.kpvpartid, p.tpvpartid, p.name, p.validfrom, p.validto, a.kpvadrsid from vista.tpvpartner p 
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
where p.cpartnertype='PartnerTyp#NNP' and a.kpvadrsid is not null; -- 30518, adresse: 31518

select * from vista.tsfmqoutbound where jmstype='BZ.BW-N001' order by lastupdated desc;
-- SIT438
select count(*) from vista.tsfmqoutbound where jmstype='BZ.BW-N001' and reason is not null; -- 1641353
select count(*) from vista.tsfmqoutbound where jmstype='BZ.BW-N001' and reason='MQOUTBREJ#BEANERROR' and lastupdated >= '2019-09-20'; -- 127918



-- Finding 68105: Invalid Outbound-XML for LZ.IK-RR001
SELECT * FROM vista.TSFMQINBOUND inb , vista.tsfmqoutbound outb
WHERE inb.lastupdated >'2019-09-20' AND inb.jmstype='LZ.IK-RR001' AND inb.username  LIKE 'besit%'
AND inb.JMSCORRELATIONID= outb.JMSCORRELATIONID
AND outb.reason='MQOUTBREJ#INVOUTXML';

-- not working (no BW data)
select o.kpvroleid, b.*, p.* from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikaccount a on (a.tikacctid = b.tikacctid)
left join vista.tikheader h on (h.tikheadid = a.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
where h.vnr='7569371001939'; -- 305997743

-- not working (BW data & non-BW)
select * from vista.tikbooking where tikbookid=140582523; -- TIKACCTID =  126172216
select * from vista.tikaccount where tikacctid=126172216; -- TIKHEADID = 126172213
select * from vista.tikheader where tikheadid=126172213;
select * from vista.tikheader where tikownrid=1649963;

select o.kpvroleid, b.*, p.* from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikaccount a on (a.tikacctid = b.tikacctid)
left join vista.tikheader h on (h.tikheadid = a.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
where o.tikownrid = (select h2.tikownrid from vista.tikheader h2 where h2.vnr='7561230488530'); --301398220

-- working (no BW, processId)
select o.kpvroleid, b.*, p.* from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikaccount a on (a.tikacctid = b.tikacctid)
left join vista.tikheader h on (h.tikheadid = a.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
where h.vnr='7565818588964'; -- 301676768

-- working (all with BW)
select o.kpvroleid, b.*, p.* from vista.tikbooking b
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
left join vista.tikaccount a on (a.tikacctid = b.tikacctid)
left join vista.tikheader h on (h.tikheadid = a.tikheadid)
left join vista.tikowner o on (o.tikownrid = h.tikownrid)
where h.vnr='7565717322836'; -- 305997367


select * from vista.tpvpaymentaddr where iban like 'DE%'; -- DE89370400440532013000
select * from vista.tpvbankbasic where kpvbankid=9500000004211701; -- 37040044

-- Problem: only BWENTRYOID is set, but not BWLISTOID.
select count(*) as cnt_bw_book from vista.tikbooking where (bwlistoid is null and bwentryoid is not null) or (bwlistoid is not null and bwentryoid is null); 
-- SIT438: 260262 @ 13 sec; ZH: 0
select count(*) as cnt_bw_book from vista.tikbooking where (bwlistoid is null and bwentryoid is not null); -- 260262

-- Foreign IBAN
SELECT * FROM vista.TPVPAYMENTADDR pa
LEFT JOIN vista.TPVBANKBASIC bb ON (pa.KPVBANKID=bb.KPVBANKID)
LEFT JOIN vista.tpvpartner p ON (p.kpvpartid=pa.KPVPARTID)
WHERE p.CPARTNERTYPE='PartnerTyp#NNP';

-- ZIK-Order
select * from vista.tikzikorder where orderdate = current date order by lastupdated desc;
select tikziorid, tikheadid, orderdate, csz, binternalorder, vnr, cresidancecode, lastupdated from vista.tikzikorder where orderdate = current date order by lastupdated desc;


--
select * from vista.abdpostfilestreet where polgname = '(err)'; -- empty -- where zip6='954700';
select * from vista.abdpostfilezip; 

--
select * from vista.jpvrolerel order by lastupdated desc;

-- Frage AndrÃƒÆ’Ã‚Â© / Pepe (Rollen)
select count(rr.kpvrrelid) from vista.tpvrolerel rr
left join vista.tpvrole r1 on (r1.kpvroleid = rr.kpvroleid_source)
left join vista.tpvrole r2 on (r2.kpvroleid = rr.kpvroleid_target)
where (r1.croletype='Rolle#IK' or r2.croletype='Rolle#IK')
and rr.validto > current date; -- SG: 276 / ZH: 1688

select c.code_id, c.shortcode, c.codetypeno, c.codeno, c.const_field, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id  like 'Correspond#%' and shortcode like 'FA%'
order by c.value;
/*
CODE_ID          SHORTCODE   CODETYPENO  CODENO    CONST_FIELD                       VALUE            LONG_DESCRIPT  
---------------  ----------  ----------  --------  --------------------------------  ---------------  -------------  
Correspond#FAKK  FAKK        1022619     34384618  CORRESPONDENCEADDRESSEETYPE_FAKK  BusinessAp#FAK2  Kopie          
Correspond#FAKO  FAKO        1022619     34749640  CORRESPONDENCEADDRESSEETYPE_FAKO  BusinessAp#FAK2  Original       
Correspond#FAB   FAB         1022619     1022700   CORRESPONDENCEADDRESSEETYPE_FAB   BusinessAp#FZ    Betreibung     
Correspond#FAK   FAK         1022619     1022703   CORRESPONDENCEADDRESSEETYPE_FAK   BusinessAp#FZ    Kopie          
Correspond#FAO   FAO         1022619     1022706   CORRESPONDENCEADDRESSEETYPE_FAO   BusinessAp#FZ    Original     
*/
update vista.tiscmcode c set c.value='BusinessAp#FAK', c.uuser='TA2xxxxx', c.utst=current timestamp 
where c.const_field in ('CORRESPONDENCEADDRESSEETYPE_FAB', 'CORRESPONDENCEADDRESSEETYPE_FAK', 'CORRESPONDENCEADDRESSEETYPE_FAO') 
and c.code_id in ('Correspond#FAB', 'Correspond#FAK', 'Correspond#FAO');

select program, count(*) as cnt_create from vista.jpvpartner where operation='I' group by program;

select program, count(*) as cnt_create from vista.jikzikorder where operation='I' group by program;

select * from vista.tikzikorder order by lastupdated desc;

-- Defect 68844 Fehler bei Lohnlisten-Erfassung
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and jmsmessageid='ID:36c0c173-1cca-43ab-85b9-3dff50221561'; -- empty
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and jmsmessageid='ID:36c0c173-1cca-43ab-85b9-3dff50221561'; -- empty --ID:414d51204142583134313753202020208a667d5d2309df02
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and jmsmessageid='ID: 414d51204142583134313753202020208a667d5d2309df02'; --  empty ID:414d51204142583134313753202020208a667d5d2309df02
-- correlationID: [cae46c07-f530-4c1d-81ee-705431ac4d7e]
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and jmscorrelationid='cae46c07-f530-4c1d-81ee-705431ac4d7e';
/*
TSFMQOUTBOUNDID  STATUS  REASON               EXECTIMEMDB  EXECTIMESRV  JMSMESSAGECLASS  JMSTYPE      JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                                    JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC                           USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  OUTBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        LASTUPDATED          
---------------  ------  -------------------  -----------  -----------  ---------------  -----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  ------------------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  ------------------------------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
2178540557       0       MQOUTBREJ#INVOUTXML  234          62           JMSTextMessage   LZ.IK-RR001  2                0              4            ID:414d51205453533134313753202020204dad7e5d25d74e28  1570698108098  cae46c07-f530-4c1d-81ee-705431ac4d7e  queue://ABX1417S/BZBW.LZIK.RR001.DATA.SEARCH.REP  (null)      0               bootstrap.WSPreLauncher       0                  svcmqslz0     (null)                 (null)            (null)          (null)           28                   20191010         09014783         dbad44a2-f1bc-4bec-b1a0-543c40a31d02  SG        BZ/LZIK/RR001/DataSearch/Reply  sgsit041  de                (null)              2.1      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:IGS-IKAbfrageBuchungenResponse xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns6="https://igs-gmbh.ch/xmlns/igs-0016/2" xmlns:ns5="https://igs-gmbh.ch/xmlns/igs-0007/2" xmlns:ns7="https://igs-gmbh.ch/xmlns/igs-0008/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0015/2" xmlns:ns4="https://igs-gmbh.ch/xmlns/igs-0014/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0017/2">
*/
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and jmscorrelationid='cae46c07-f530-4c1d-81ee-705431ac4d7e'; -- 350900 / 7563980068093
select * from vista.tikheader where vnr='7563980068093';
/*
TIKHEADID  TIKOWNRID  VNR            NAME            BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  --------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
79938837   77230472   7563980068093  PASTERK,DANIEL  1983       9           29        SEXCODEZAS#1  BSVLAND#229  70383391154    T                2010-09-22 12:59:15  
*/
select * from vista.tikowner where tikownrid=77230472; -- 72957056
select * from vista.tikemployerarchive where billnbr='350900';
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1         ADR2                    ADR3             ADR4             KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -------  ----------  -----------  -----------  ----------------------  ---------------  ---------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
597074204  350900   (null)      BRANCHE#84   Personalamt  des Kantons St. Gallen  Davidstrasse 35  9000 St. Gallen  14849949        CHE114965275  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#J  73346                 64696             28986                 64696                     1948-01-01  9999-12-31  cbe05462-5f66-4d39-be12-d9dac0d5728d  10612613    10612613        14849949            SONDERFALL#03  956577    MEMBERTYP#AK  2019-06-14 20:46:09  
*/
select * from vista.tikbooking where billnbr='350900'; -- >200

select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and jmscorrelationid='cae46c07-f530-4c1d-81ee-705431ac4d7e'; -- 350900 / 7563980068093
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and inboundmsg like '%<ns2:billNumber>350900</ns2:billNumber>%' and lastupdated > '2019-10-01';
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and inboundmsg like '%<ns2:insuranceNumber>7563980068093</ns2:insuranceNumber>%' and lastupdated > '2019-10-01';

-- Streetfile issues in RDC
select * from vista.ABDPOSTFILEZIP zip; -- where zip.ZIP6 = '954700';
select * from vista.abdpostfilestreet s where s.ZIP6 = '954700'; -- 174
select * from vista.abdpostfilestreet s where s.ZIP6 = '954700' and s.street is null; -- DCENTRAL: empty / RDCCB301: empty

select * from vista.abdpostfilezip zip where zip4 in (8303, 8180);


-- MQ: Messages nicht generiert auf SIT
select distinct jmstype from vista.tsfmqinbound; -- neuester Event: 2019-09-06 15:04:00
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' order by lastupdated desc; -- neuester Event: 2019-09-06 15:04:00
select * from vista.tsfmqevent order by lastupdated desc; -- neuester Event: 2019-10-14 13:35:04

select * from vista.tpvPARTNER where kpvpartid = 1163691;
update vista.tpvPARTNER set lastupdated set current timestamp where tpvpartid = 1163739;


-- 67286 - PV.2019.62071 - Zuordnung POLG zu WS/GS: Endlos-Loop - Endlos-Loop ist immer noch vorhanden

-- BCJMQEVT01 / ResponseXsdVersion
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id in ('')
order by c.value;



-- IK.2019.69121 Bewirtschaftung IK-Kurzregister: Zuteilung Adressierung fÃƒÆ’Ã‚Â¼r ungÃƒÆ’Ã‚Â¼ltige AdressIDs aus B&Z (BZ.BW-N001)
select * from vista.tikemployerarchive where bwregisteroid is not null and edv2000partnerid is not null;
select * from vista.tikemployerarchive where edv2000partnerid is null and bwregisteroid is not null;
-- AIT101
select * from vista.tikemployerarchive where edv2000partnerid is null or tikearcid=9500000000275000;
-- Register-Adresse --> (minus)edv2000partnerid / Korrespondenz-Adresse --> (minus)edv2000corraddrpartnerid
update vista.tikemployerarchive set edv2000partnerid=-9500000000275000, edv2000corraddrpartnerid=-9500000000275000, lastupdated=current timestamp where tikearcid=9500000000275000;

select * from vista.tommessage msg 
left join vista.tommesgparameter par on (par.tommesgid = msg.tommesgid)
where msg.ccontextid='CONTEXT#IK';

select msg.tommesgid, msg.cmessagetypeid, msg.cmessageseverityid, msg.ccontextid, par.value from vista.tommessage msg 
left join vista.tommesgparameter par on (par.tommesgid = msg.tommesgid)
where msg.ccontextid='CONTEXT#IK';


-- KOAU via DOPiX: attachment table:
select * from vista.TZASEDEXATTACHMENT;
Select * from vista.TZAXMLSDXRECORD where MESSAGETYPE = '2050' and SUBMESSAGETYPE = '000402';
select distinct errorcode, errormessage, count(*) as cnt_err from vista.tikkoaurequest group by errorcode, errormessage;
/*
ERRORCODE  ERRORMESSAGE                                                                        CNT_ERR  
---------  ----------------------------------------------------------------------------------  -------  
3          Antrag wurde von ZAS abgelehnt                                                      670      
1          Die Versichertennummer ist ungÃƒÆ’Ã‚Â¼ltig.                                                15       
3          Ein IK-Auszug mit SZ 97 wurde bereits innerhalb der letzten 6 Monate bearbeitet.    756      
2          Es besteht fÃƒÆ’Ã‚Â¼r eine verkettete Vers.Nr. fÃƒÆ’Ã‚Â¼r diese Beitragsperiode ein RentenZIK     186      
4          Es ist kein IK fÃƒÆ’Ã‚Â¼r den Versicherten vorhanden.                                      429      
4          Es werden keine IK's erwartet                                                       1179     
4          Es werden keine IKÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢s erwartet                                                       433      
5          FÃƒÆ’Ã‚Â¼r diese Beitragsperiode wurden eigene Renten-ZIK-Daten hinzugefÃƒÆ’Ã‚Â¼gt.               511      
2          FÃƒÆ’Ã‚Â¼r diese Versichertennummer ist bereits ein Splitting Antrag im System vorhanden.  1        
2          FÃƒÆ’Ã‚Â¼r diese Versichertennummer ist bereits eine Sammlung in der Verarbeitung.         45       
0          (null)                                                                              62151    
*/
select distinct errorcode, errormessage, count(*) as cnt_err from vista.tikkoaurequest where senderid='SEDEX' group by errorcode, errormessage ;

select distinct errorcode, errormessage, count(*) as cnt_err from vista.tikkoaurequest group by errorcode, errormessage;
select count(distinct requestid) as cnt_koau from vista.tikkoaurequest where date(lastupdated) >= '2019-10-01'; -- prodSG: 665, prodZH: 2266
select month(lastupdated) as monat, count(distinct requestid) as cnt_koau from vista.tikkoaurequest where date(lastupdated) >= '2019-01-01' group by month(lastupdated); -- prodSG: 665, prodZH: 2266
/*
MONAT  CNT_KOAU  
-----  --------  
1      757       
2      1779      
3      991       
4      1493      
5      1017      
6      2837      
7      2917      
8      1573      
9      761       
10     2266      
*/

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'SDX2050%'
order by c.value;
/*
CODE_ID             SHORTCODE   VALUE                  LONG_DESCRIPT                    
------------------  ----------  ---------------------  -------------------------------  
SDX2050#PHONE       PHONE       0444444444             2050 phone                       
SDX2050#VERSION     VERSION     1.0                    2050 Version                     
SDX2050#OTHER       OTHER       Chef-TÃƒÂ¤ster BE         2050 other                       
SDX2050#MANUFACT    MANUFACT    IGS/IBM                2050 Manufacturer                
SDX2050#DEPARTMENT  DEPARTMENT  Indiv. Konto           2050 department                  
SDX2050#NAME        NAME        Jonas Grimm            2050 Name                        
SDX2050#EMAIL       EMAIL       Jonas.Grimm@akbern.ch  2050 email                       
SDX2050#REQTYPE     REQTYPE     SEDEX                  Text fÃƒÆ’Ã‚Â¼r SEDEX Markierung        
SDX2050#SZKOAUREQ   SZKOAUREQ   SZMZR#98               SZ fÃƒÆ’Ã‚Â¼r Sedex KOAU Antrag (2050)  
SDX2050#PRODUCT     PRODUCT     Vista L&Z              2050 Product                     
*/
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'IKCONST%'
order by c.value;


-- 21504 - SEDEX - TF8 - lastupdated for XML reply not set
Select * from vista.TZAXMLSDXRECORD where MESSAGETYPE = '2050' and SUBMESSAGETYPE = '000402';

-- Default-Sprache Deutsch
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'CorresLang%'
order by c.value;
/*
CODE_ID       SHORTCODE   VALUE  LONG_DESCRIPT  
------------  ----------  -----  -------------  
CorresLang#D  D           1      Deutsch                                                            
*/
select * from vista.tiscmcode c where code_id='CorresLang#D'; -- codetypeno = 1023681, codeno = 1023684
update vista.tiscmcode set code_id='CorresLang#I', shortcode='I', const_field='CORRESLANGUAGE_I' where codetypeno = 1023681 and codeno = 1023684;
update vista.tiscmcode set code_id='CorresLang#D', shortcode='D', const_field='CORRESLANGUAGE_D' where codetypeno = 1023681 and codeno = 1023684;


select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like '%DatBilAbko%'
order by c.value;

select * from vista.tikemployerarchive;

-- Defect 21644 - [iFix Candidate] IK Abfrage in B&Z nicht korrekt - Buchungen werden mehrfach von L&Z geliefert (LZ.IK-RR001)
-- CASE 1:
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and jmscorrelationid='41f95661-d2c2-4988-8f99-0647521116e3'; -- empty
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and jmscorrelationid='ad69aa6f-116f-46ed-ac28-1383cad9c948'; -- empty
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and businessprocessid='ba0e042e-612d-418f-bb7a-a2f8c78d71bf'; -- ok; jmscorrelationid = '4e2cf8ac-9009-4e50-93f5-b8b384c3b30e'
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and businessprocessid='ba0e042e-612d-418f-bb7a-a2f8c78d71bf'; -- ok
select * from vista.tikheader where vnr='57150501115'; -- tikownrid=78082263
select * from vista.tikowner where tikownrid=78082263; -- kpvroleid=76234114
-- CASE 2:
-- 756.7634.3791.46
select * from vista.tikheader where vnr='7567634379146'; -- tikownrid=77785873
select * from vista.tikowner where tikownrid=77785873; -- kpvroleid=75092004
select tikearcid, billnbr, adr1, kpvpartner, validfrom, validto from vista.tikemployerarchive where billnbr='442061';
/*
TIKEARCID  BILLNBR  ADR1                KPVPARTNER  VALIDFROM   VALIDTO     
---------  -------  ------------------  ----------  ----------  ----------  
69929563   442061   GAGLIO FRANCO       (null)      1981-07-01  1982-12-31  
597092893  442061   BÃƒÂ¤umlin & Ernst AG  11025627    1996-01-01  9999-12-31  
*/
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and businessprocessid='dbc83e81-2b75-4cdf-a167-f99653f27c0f'; -- ok
-- CASE 3:
-- 7560267978373
select * from vista.tikheader where vnr='7560267978373'; -- tikownrid=875186709
select * from vista.tikowner where tikownrid=875186709; -- kpvroleid=875186707
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-10-31' and businessprocessid='ad42c617-7d05-4da1-bda4-fd25e236679c'; -- ok

-- Pension-SZ:
select c.code_id, d.long_descript,
(
    CASE WHEN c.shortcode > '70' AND c.shortcode < '90' THEN 'x' END
) as pension
from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'SZMZR%'
order by c.value;
/*
CODE_ID   LONG_DESCRIPT                                                                                PENSION  
--------  -------------------------------------------------------------------------------------------  -------  
SZMZR#02  Zusammenruf der  IK                                                                          (null)   
SZMZR#11  VA ohne IK - Beitragspflicht                                                                 (null)   
SZMZR#13  VA ohne IK - Nichtbeitragspflichtige/r                                                       (null)   
SZMZR#15  VA ohne IK - Mutation                                                                        (null)   
SZMZR#16  Korrektur aktuelle VNR                                                                       (null)   
SZMZR#19  VA ohne IK - ohne Beitragspflicht                                                            (null)   
SZMZR#21  VA mit IK - Beitragspflicht                                                                  (null)   
SZMZR#22  VA mit IK - Beitragspflicht (alt)                                                            (null)   
SZMZR#25  VA mit IK - Mutation                                                                         (null)   
SZMZR#26  VA mit IK - Mutation (alt)                                                                   (null)   
SZMZR#31  VA ohne IK - Ersatz                                                                          (null)   
SZMZR#32  VNR bei ZAS ergÃƒÂ¤nzen                                                                         (null)   
SZMZR#33  VA ohne IK - Ersatz b. Vorlage                                                               (null)   
SZMZR#35  VA ohne IK - ohne VA vor ZIK                                                                 (null)   
SZMZR#36  Erstmaliger VA ohne IK-ErÃƒÆ’Ã‚Â¶ffnung wegen NN                                                    (null)   
SZMZR#40  Druck VN                                                                                     (null)   
SZMZR#41  VA mit IK - Ersatz                                                                           (null)   
SZMZR#42  VA mit IK - Ersatz (alt)                                                                     (null)   
SZMZR#43  VA mit IK - Ersatz b. Vorlage                                                                (null)   
SZMZR#44  VA mit IK - Ersatz b. Vorlage (alt)                                                          (null)   
SZMZR#46  Erstmaliger VA mit IK-ErÃƒÆ’Ã‚Â¶ffnung wegen NN                                                     (null)   
SZMZR#61  IK ohne VA - bei Vorlage VA                                                                  (null)   
SZMZR#62  IK ohne VA - bei Vorlage VA (alt)                                                            (null)   
SZMZR#63  IK ohne VA - ohne Vorlage VA                                                                 (null)   
SZMZR#64  IK ohne VA - ohne Vorlage VA (alt)                                                           (null)   
SZMZR#65  IK ohne VA - Abschluss IK                                                                    (null)   
SZMZR#66  IK ohne VA - Abschluss IK (alt)                                                              (null)   
SZMZR#67  IK ohne VA - Rentenalter                                                                     (null)   
SZMZR#68  Erstmalige IK-ErÃƒÆ’Ã‚Â¶ffnung wegen NN                                                             (null)   
SZMZR#71  ZIK AHV ohne IK                                                                              x        
SZMZR#72  Zusammenruf der IK im Falle einer AHV-Rentenneuberechnung nach Erreichen des Referenzalters  x        
SZMZR#73  ZIK AHV ohne IK (alt)                                                                        x        
SZMZR#75  ZIK IV ohne IK                                                                               x        
SZMZR#77  ZIK IV ohne IK (alt)                                                                         x        
SZMZR#79  ZIK RÃƒÆ’Ã‚Â¼ckvergÃƒÆ’Ã‚Â¼tung ohne IK                                                                    x        
SZMZR#81  ZIK AHV mit IK                                                                               x        
SZMZR#83  ZIK AHV mit IK (alt)                                                                         x        
SZMZR#84  ZIK AHV mit IK (alt)                                                                         x        
SZMZR#85  ZIK IV mit IK                                                                                x        
SZMZR#86  ZIK IV mit IK (alt)                                                                          x        
SZMZR#90  Zusammenruf von IK-Kopien im Falle der GewÃƒÂ¤hrung einer vorgezogenen Rente                    (null)   
SZMZR#91  ZIK Waisen-/Kinderrente ohne IK (alt)                                                        (null)   
SZMZR#92  ZIK Rentenvorausberechnung                                                                   (null)   
SZMZR#93  ZIK IK-Kopien z.Hd. AK                                                                       (null)   
SZMZR#94  ZIK IK-Kopien CH-Beitr.zeiten                                                                (null)   
SZMZR#95  Splitting-Auftrag                                                                            (null)   
SZMZR#96  RÃƒÆ’Ã‚Â¼ckgÃƒÂ¤ngigmachung Splitting-A.                                                               (null)   
SZMZR#97  ZIK z. Hd. Versicherten                                                                      (null)   
SZMZR#98  ZIK z. Hd. Versicherten                                                                      (null)   
SZMZR#99  RÃƒÆ’Ã‚Â¼ckgÃƒÂ¤ngigmachung ZIK                                                                        (null)   
*/
-- ENGLISH:
/*
CODE_ID   LONG_DESCRIPT                                                              PENSION  
--------  -------------------------------------------------------------------------  -------  
SZMZR#02  Individual account summary                                                 (null)   
SZMZR#11  VA without IK - dues duty                                                  (null)   
SZMZR#13  VA without IK - Person without dues duty                                   (null)   
SZMZR#15  VA ohne IK - Change                                                        (null)   
SZMZR#16  Correction current VNR                                                     (null)   
SZMZR#19  VA without IK - without dues duty                                          (null)   
SZMZR#21  VA with IK - dues duty                                                     (null)   
SZMZR#22  VA with IK - dues duty (old)                                               (null)   
SZMZR#25  VA with IK - Change                                                        (null)   
SZMZR#26  VA with IK - Change (old)                                                  (null)   
SZMZR#31  VA without IK - Substitute                                                 (null)   
SZMZR#32  Complement VNR at ZAS                                                      (null)   
SZMZR#33  VA without IK - Substitute Presentation                                    (null)   
SZMZR#35  VA without IK - without VA before ZIK                                      (null)   
SZMZR#36  First VA without IK replaces grey card                                     (null)   
SZMZR#40  Print VN                                                                   (null)   
SZMZR#41  VA with IK - Substitute                                                    (null)   
SZMZR#42  VA with IK - Substitute (old)                                              (null)   
SZMZR#43  VA with IK. Substitute VA at presenting                                    (null)   
SZMZR#44  VA with IK - Substitute VA at presenting (o)                               (null)   
SZMZR#46  First VA with IK replaces grey card                                        (null)   
SZMZR#61  IK without VA - with presenting VA                                         (null)   
SZMZR#62  IK without VA - with presenting VA (old)                                   (null)   
SZMZR#63  IK without VA - without presenting VA                                      (null)   
SZMZR#64  IK without VA - without presenting VA (old)                                (null)   
SZMZR#65  IK without VA - completion                                                 (null)   
SZMZR#66  IK without VA - completion (old)                                           (null)   
SZMZR#67  IK without VA pension age                                                  (null)   
SZMZR#68  First IK opening with new VNr (NNSS)                                       (null)   
SZMZR#71  ZIK AHV ohne IK                                                            x        
SZMZR#72  ZIK 72                                                                     x        
SZMZR#73  ZIK AHV ohne IK (old)                                                      x        
SZMZR#75  ZIK IV ohne IK                                                             x        
SZMZR#77  ZIK IV ohne IK (alt)                                                       x        
SZMZR#79  ZIK reimbursement without IK                                               x        
SZMZR#81  ZIK AHV with IK                                                            x        
SZMZR#83  ZIK AHV with IK (old)                                                      x        
SZMZR#84  ZIK AHV with IK (old)                                                      x        
SZMZR#85  ZIK IV with IK                                                             x        
SZMZR#86  ZIK IV with IK (old)                                                       x        
SZMZR#90  Zusammenruf von IK-Kopien im Falle der GewÃƒÂ¤hrung einer vorgezogenen Rente  (null)   
SZMZR#91  ZIK orphan pension without IK (old)                                        (null)   
SZMZR#92  ZIK Pension calculation ahead                                              (null)   
SZMZR#93  ZIK IK-Copies to insured                                                   (null)   
SZMZR#94  ZIK IK Copies CH due times                                                 (null)   
SZMZR#95  Splitting task                                                             (null)   
SZMZR#96  Cancel splitting                                                           (null)   
SZMZR#97  ZIK to insured                                                             (null)   
SZMZR#98  ZIK to insured                                                             (null)   
SZMZR#99  Cancel ZIK                                                                 (null)   
*/

-- Defect 21835: IKJB10101 endet mit Exception wenn Notifikation LZ.IK-N001 aktiviert ist
/*
Testplan: I1903.2 - P.12.50.002 / SIT417
Der Ziel des Tests war es, dass eine Notifiations-Message LZ.IK-N001 erstellt wird. Dazu wird vorgÃƒÂ¤ngig im CM der IK/IKCONST/EANOTIFY auf 'J' gestellt 
und ein VA/IK-Antrag SZ 61 fÃƒÂ¼r einen Versicherten erstellt, welcher bei einem Mitglied AG oder BGSA beschÃƒÂ¤ftigt ist.
Versicherten-Nr. 756.7717.3984.77 HUNZIKER,ANDREA
*/
select * from vista.tikheader where vnr='7567717398477'; -- empty
select * from vista.tikrequestheader where pendvnr='7567717398477'; -- empty
select * from vista.tpvpartner where personid='7567717398477';
select * from vista.aurupiregister where new_nnss='7567717398477';
select * from vista.tikvaikrequest order by lastupdated desc;
select * from vista.tikvaikrequest where tikvaikreqid=2208248803;
/*
TIKVAIKREQID  KPVROLEID  TIKVIOOID   DELIVERYADDRESSIK  DELIVERYADDRESSPK  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CPENDPROTECTIONCODE  BHASALREADYIK  BILLNO  ENTRYDATE   INSURANCEPROOFPRINTDATE  INSURANCECERTPRINTDATE  BPRINTINSURANCEPROOF  PRINTINGLANGUAGE  LASTUPDATED          
------------  ---------  ----------  -----------------  -----------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -------------------  -------------  ------  ----------  -----------------------  ----------------------  --------------------  ----------------  -------------------  
2208248803    538774554  2208248801  2208248802         (null)             SZMZR#61  SGSIT051  2019-11-07   729227  (null)            (null)          MZRFEHLER#-1     (null)                SGsit051   Protection#0         (null)         350900  2019-01-01  (null)                   (null)                  1                     CorresLang#D      2019-11-07 08:15:54  
*/
select * from vista.tikinsurancerequest where tikviooid=2208248801;
/*
TIKVIOOID   CUSTOMER  CORRESPONCEADDRESSID  BPRINTID  BZASCOMPLETED  PRINTORDERDATE  VISTADOCREF  LASTUPDATED          
----------  --------  --------------------  --------  -------------  --------------  -----------  -------------------  
2208248801  (null)    (null)                0         0              (null)          (null)       2019-11-07 08:15:54  
*/
select * from vista.tikrequestheader where tikvaikreqid=2208248803;
/*
TIKRQHEID   TIKVAIKREQID  TIKZIKREQID  TIKSPLITTINGREQID  PENDVNR        PENDNAME   PENDFIRSTNAME  PENDNAMEZAS          PENDBIRTHYEAR  PENDBIRTHMONTH  PENDBIRTHDAY  CPENDSEX      CPENDCOUNTRY  PRIORITY  LASTUPDATED          
----------  ------------  -----------  -----------------  -------------  ---------  -------------  -------------------  -------------  --------------  ------------  ------------  ------------  --------  -------------------  
2208248804  2208248803    (null)       (null)             7569346485214  PALMISANO  PATCHAREE      PALMISANO,PATCHAREE  1984           11              13            SEXCODEZAS#2  BSVLAND#100   0         2019-11-07 08:15:54  
*/
select * from vista.tpvrole where kpvroleid=538774554;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
538774553  538774554  1817618    Rolle#IK   (null)     (null)       (null)  2001-01-01  9999-12-31  2013-08-15 14:40:33  
*/
select * from vista.tikowner where kpvroleid=538774554; -- 538774563
select * from vista.tikheader where tikownrid=538774563;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                      BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
79988885   538774563  77984844215    SAWETWONGSAKUL,PATCHAREE  1984       11          13        SEXCODEZAS#2  BSVLAND#100                 T                2013-08-15 14:40:34  
539003642  538774563  7569346485214  PALMISANO,PATCHAREE       1984       11          13        SEXCODEZAS#2  BSVLAND#100  77984844215    F                2016-08-05 02:19:04  
*/
select * from vista.tikemployerarchive where billnbr='350900';
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1         ADR2                    ADR3             ADR4             KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -------  ----------  -----------  -----------  ----------------------  ---------------  ---------------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
597074204  350900   (null)      BRANCHE#84   Personalamt  des Kantons St. Gallen  Davidstrasse 35  9000 St. Gallen  14849949        CHE114965275  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#J  73346                 64696             28986                 64696                     1948-01-01  9999-12-31  cbe05462-5f66-4d39-be12-d9dac0d5728d  10612613    10612613        14849949            SONDERFALL#03  956577    MEMBERTYP#AK  2019-06-14 20:46:09  
*/
select * from vista.aurupiregister where new_nnss='7569346485214';

-- 216432 - prodSO: LuZ PV unberechtigte USER EintrÃƒÂ¤ge Bieri Ursula
select tpvpartid, kpvpartid, personid, name, validfrom, validto, cconfidlevel, change_date, change_user, program, operation 
from vista.jpvpartner where personid='7563099602393' order by tpvpartid, change_date desc; -- 3182329

select p.tpvpartid, p.kpvpartid, p.personid, p.name, p.validfrom, p.validto, p.cconfidlevel, j.cconfidlevel as old_cconfidlevel, j.change_date, j.change_user, j.program, j.operation 
from vista.tpvpartner p
left join vista.jpvpartner j on (j.tpvpartid = p.tpvpartid and j.change_date = (select max(j2.change_date) from vista.jpvpartner j2 where j2.tpvpartid = p.tpvpartid) )
where p.personid='7563099602393' order by p.tpvpartid desc; -- 3182329

-- 21028: [TA214752] Modifying a corr role relations from NNP to NP recipient through interfaces does not clear the contact person information
select p.kpvpartid, p.personid, rr.* from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source)
left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid)
where rr.crelationtype='RoleRelati#KE' and rr.ccorraddresseetype='Correspond#ELDO'; -- 9500000003628727 / rr: 9500000003629045

select * from vista.tpvrolerel where tpvrrelid=9500000003629045;

--
select * from vista.tpvfamilyrel;

-- Defect 22004 - [iFix Candidate] [iFix Candidate] LZ.IK-RR001 booking data for multi-period employers
-- CASE 1:
select * from vista.tsfmqoutbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-11-12' and outboundmsg like '%146993%'; -- 3 entries
select * from vista.tsfmqinbound where jmstype='LZ.IK-RR001' and date(lastupdated) = '2019-11-12' and businessprocessid='4fcc1f53-862c-408f-b9f2-a19e51aaf9d7'; -- ok
select * from vista.tikheader where vnr='7561704796901'; -- tikownrid=76877056
select * from vista.tikowner where tikownrid=76877056; -- kpvroleid=71618529

select DISTINCT( b.TIKBOOKID), b.BILLNBR, b.CSTORNOCODE, b.CCONTRIBUTIONTYPE, b.TIKBOPEID, b.INCOME, b.TIKACCTID, b.BOOKEDBY, b.BOOKINGDATE, 
b.PENDVNR, b.PENDNAME, b.PENDFIRSTNAME, b.BWLISTOID, b.NBRINSURED, b.BWRITEOFFCODE, b.CSECTOR, b.CTOWNSHIP, b.BWDECREEOID, b.CCODEADS, 
b.BASYLUMCODE, b.CCARETAKINGFACTOR, b.SPOUSEVNR, b.BWENTRYOID, p.REFYEAR, p.ENDDATE, p.BEGINDATE, p.CSPECIALITY, p.ENDMONTH, p.BEGINMONTH, 
sxbk.tiksexcid, acc.CACCOUNTTYPE, hd.VNR, ea.ADR1, zor.CSZ, zor.CLOSINGDATE, p.NBRMONTHS,
pv.kpvpartid, pv.name, pv.additionalname, pv.validfrom as pv_validfrom, pv.validto as pv_validto,
edv.vista_kpv_key,
edv_pv.kpvpartid as edv_pv_kpvpartid, edv_pv.name as edv_pv_name, edv_pv.additionalname as edv_pv_additionalname, edv_pv.validfrom as edv_pv_validfrom, edv_pv.validto as edv_pv_validto
from vista.TIKBOOKING b  left join vista.TIKPERIOD p 
on (p.tikbopeid = b.tikbopeid) left join vista.TIKSEXC_TIKBOOK sxbk on (sxbk.tikbookid = b.tikbookid) left join vista.TIKZEXC_TIKBOOK zxbk 
on (zxbk.tikbookid = b.tikbookid)left join vista.TIKZIKEXECUTION zex on (zex.tikzexcid = zxbk.tikzexcid) left join vista.TIKACCOUNT acc 
on (acc.TIKACCTID = b.TIKACCTID)left join vista.TIKHEADER hd on (acc.TIKHEADID = hd.TIKHEADID)left join vista.TIKZIKORDER zor 
on (zor.TIKZIORID = zex.TIKZIORID)left join vista.TIKEMPLOYERARCHIVE ea on (ea.billnbr = b.billnbr) 
left join vista.tpvpartner pv on (pv.kpvpartid = ea.kpvpartner)
left join vista.tbikeymapping2000 edv on (edv.edv2000_zid_key = ea.edv2000partnerid)
left join vista.tpvpartner edv_pv on (edv_pv.kpvpartid = edv.vista_kpv_key)
where b.billnbr = '146993';  ---b.TIKBOOKID in ();

select b.TIKBOOKID, b.BILLNBR, b.CSTORNOCODE, b.CCONTRIBUTIONTYPE, b.TIKBOPEID, b.INCOME, b.TIKACCTID, b.BOOKEDBY, b.BOOKINGDATE, b.PENDVNR, b.PENDNAME, b.PENDFIRSTNAME, 
b.BWLISTOID, b.NBRINSURED, b.BWRITEOFFCODE, b.CSECTOR, b.CTOWNSHIP, b.BWDECREEOID, b.CCODEADS, b.BASYLUMCODE, b.CCARETAKINGFACTOR, b.SPOUSEVNR, b.BWENTRYOID, 
p.REFYEAR, p.ENDDATE, p.BEGINDATE, p.CSPECIALITY, p.ENDMONTH, p.BEGINMONTH, sxbk.tiksexcid, acc.CACCOUNTTYPE, hd.VNR, ea.ADR1, zor.CSZ, zor.CLOSINGDATE, p.NBRMONTHS, 
ea.VALIDFROM, pv.kpvpartid, pv.name, pv.firstname, pv.validfrom as pv_validfrom, pv.validto as pv_validto, edv.vista_kpv_key, 
edv_pv.kpvpartid as edv_pv_kpvpartid, edv_pv.name as edv_pv_name, edv_pv.firstname as edv_pv_firstname, edv_pv.validfrom as edv_pv_validfrom, edv_pv.validto as edv_pv_validto, 
pv.CPARTNERTYPE, ea.KPVPARTNER, ea.EDV2000PARTNERID from vista.TIKBOOKING b  
left join vista.TIKPERIOD p on (p.tikbopeid = b.tikbopeid) 
left join vista.TIKSEXC_TIKBOOK sxbk on (sxbk.tikbookid = b.tikbookid) 
left join vista.TIKZEXC_TIKBOOK zxbk on (zxbk.tikbookid = b.tikbookid)
left join vista.TIKZIKEXECUTION zex on (zex.tikzexcid = zxbk.tikzexcid) 
left join vista.TIKACCOUNT acc on (acc.TIKACCTID = b.TIKACCTID)
left join vista.TIKHEADER hd on (acc.TIKHEADID = hd.TIKHEADID)
left join vista.TIKZIKORDER zor on (zor.TIKZIORID = zex.TIKZIORID)
left join vista.TIKEMPLOYERARCHIVE ea on (ea.billnbr = b.billnbr)
left join vista.tpvpartner pv on (pv.kpvpartid = ea.kpvpartner)
left join vista.tbikeymapping2000 edv on (edv.edv2000_zid_key = ea.edv2000partnerid)
left join vista.tpvpartner edv_pv on (edv_pv.kpvpartid = edv.vista_kpv_key)
where b.TIKBOOKID in  (select bk.TIKBOOKID from vista.TIKBOOKING bk  inner join vista.TIKPERIOD bkp on bk.TIKBOPEID = bkp.TIKBOPEID  
inner join vista.TIKACCOUNT acc on bk.TIKACCTID = acc.TIKACCTID  left outer join vista.TIKHEADER hd on acc.TIKHEADID = hd.TIKHEADID  
where ( bk.CLASTACTION != 'IKBUCHHIST#d'  or bk.CLASTACTION is NULL ) and hd.VNR in ('14463459119','7561704796901') 
UNION  select bk1.TIKBOOKID from vista.TIKBOOKING bk1   inner join vista.TIKPERIOD bkp1 on bk1.TIKBOPEID = bkp1.TIKBOPEID  
inner join vista.TIKACCOUNT acc1 on bk1.TIKACCTID = acc1.TIKACCTID 
WHERE ( bk1.CLASTACTION != 'IKBUCHHIST#d'  or bk1.CLASTACTION is NULL ) and bk1.PENDVNR in ('14463459119','7561704796901'));

select * from vista.tikemployerarchive where billnbr='146993';
/*
TIKEARCID  BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                 ADR2                     ADR3              ADR4             KPVCORRADDRESS  UID           CREGISTERCODE      CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
---------  -------  ----------  -----------  -------------------  -----------------------  ----------------  ---------------  --------------  ------------  -----------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
69902947   146993               BRANCHE#01   STAUFFACHER MATHIAS  APPARATEBAU + METALLBAU  ENZENBÃƒÅ“HLSTR. 51  9230 FLAWIL      (null)          (null)        (null)             (null)        EADMINCODE#N  26115                 (null)            7469                  (null)                    1976-11-01  1982-12-31  (null)                                (null)      (null)          (null)              (null)         (null)    MEMBERTYP#AK  2018-03-02 07:28:35  
597032383  146993   (null)      BRANCHE#01   Ulrich Pfister       Dreilindenstrasse 44                       9011 St. Gallen  (null)          CHE110727009  ERFASSTCOD#MGPBSE  RECHTSFORM#A  EADMINCODE#N  26115                 13897             7470                  13897                     1992-09-01  9999-12-31  a0681649-faee-4c14-94ba-9183ee8e2846  1820714     1820714         12178828            SONDERFALL#02  956577    MEMBERTYP#AK  2018-03-01 18:03:58  
*/

-- PV.2019.69988 - Partnerschaft / Verwittwet - MQ-Repli
select * from vista.tpvpartner where personid in ('7560000000453', '7560000000446'); -- 7016306 / 7016311 
select * from vista.tsfmqinbound order by lastupdated desc; -- ok
select * from vista.tsfmqoutbound order by lastupdated desc; -- ignorerepl
-- export:
select * from vista.kpvpartner where kpvpartid in (7016306, 7016311);
select * from vista.tpvpartner where kpvpartid in (7016306, 7016311);
select * from vista.kpvrole where kpvroleid in (7016308, 7016313);
select * from vista.tpvrole where kpvpartid in (7016306, 7016311);
select * from vista.tpvfamilyrel where kpvpartid_source in (7016306, 7016311);

-- Defect 70097: IK Dlg 999 is displayed as grey box only with no content (21965)
select b.*, p.* from vista.tikbooking b
left join vista.tikaccount a on (a.tikacctid = b.tikacctid)
left join vista.tikheader h on (h.tikheadid = a.tikheadid)
left join vista.tikperiod p on (p.tikbopeid = b.tikbopeid)
where b.billnbr='X99123' and b.income=100 and h.vnr='54960101211' and p.enddate='2001-12-31'; -- 1057264
update vista.tikbooking set billnbr=null, lastupdated=current timestamp where tikbookid=1057264;

-- Mehrere TPVELARPID-EintrÃƒÂ¤ge pro Partner
select * from vista.tpvelarpid;

select ep1.* from vista.tpvelarpid ep1
left join vista.tpvelarpid ep2 on (ep2.kpvpartid = ep1.kpvpartid and ep2.elarpid <> ep1.elarpid and ep1.default = 1 and ep2.default = 1);

select ep1.* from vista.tpvelarpid ep1
left join vista.tpvelarpid ep2 on (ep2.kpvpartid = ep1.kpvpartid and ep2.elarpid <> ep1.elarpid)
where ep1.default = 1 and ep2.default = 1; -- ZH: 0 @ 9 sec / SG: 0 @ 4 sec.


-- Defect 64780: IK-B-302 - IKPK 25 terminierten AG Adresse wird nicht erstellt - neuer Anlauf
/*
-       756.2041.2908.31 Marlies BÃƒÂ¼rgi
-       CM-Wert IK#IKDOCPRNT#VA_SZ31_P = J
-       Report aus Batch 302 im Anhang
*/
select * from vista.tikheader where vnr='7562041290831';
/*
TIKHEADID   TIKOWNRID   VNR            NAME            BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  --------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  
1431015082  1431015081  7562041290831  BUERGI,MARLIES  1997       11          21        SEXCODEZAS#2  BSVLAND#100  (null)    T                2018-02-26 07:38:25  
*/
select * from vista.tikowner where tikownrid=1431015081; -- kpvroleid=1431015076
select * from vista.tpvaddress where kpvpartid=1431015069; -- empty
select * from vista.tzaxmlmzrrecord where entrydate >= '2019-12-04' and recorddata like '%7562041290831%';
/*
TZAXMLMZRRECORDID  TZKXMLMZRRECORDID  PARENTID  COMPENSATIONFUNDNUMBER  BRANCHOFFICENUMBER  MESSAGETYPE               RECORDDATA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  STATE  ENTRYDATE   DATECREATED  LASTUPDATED          
-----------------  -----------------  --------  ----------------------  ------------------  ------------------------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----  ----------  -----------  -------------------  
2255287690         663031             (null)    17                      0                   VAIKEmpfangsbestaetigung  <VAIKEmpfangsbestaetigung xmlns:rc="http://www.zas.admin.ch/RC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zas.admin.ch/RC">
      <KasseZweigstelle>017000</KasseZweigstelle>
      <KasseneigenerHinweis>SGSIT051</KasseneigenerHinweis>
      <Meldungsnummer>742764</Meldungsnummer>
      <Versichertennummer>7562041290831</Versichertennummer>
      <VersichertenAngaben>
        <Namen>BUERGI</Namen>
        <Vornamen>MARLIES</Vornamen>
        <Geschlecht>2</Geschlecht>
        <Geburtsdatum>1997-11-21</Geburtsdatum>
        <Heimatstaat>100</Heimatstaat>
      </VersichertenAngaben>
      <MZRSchluesselzahl>31</MZRSchluesselzahl>
      <Verarbeitungscode>0</Verarbeitungscode>
      <Bemerkung1>0</Bemerkung1>
      <Bemerkung2>0</Bemerkung2>
      <Bemerkung3>0</Bemerkung3>
    </VAIKEmpfangsbestaetigung>  6      2019-12-05  2019-12-05   2019-12-05 10:59:55  
    */
    
select * from vista.tikvaikrequest where kpvroleid=1431015076;
/*
TIKVAIKREQID  KPVROLEID   TIKVIOOID   DELIVERYADDRESSIK  DELIVERYADDRESSPK  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CPENDPROTECTIONCODE  BHASALREADYIK  BILLNO  ENTRYDATE   INSURANCEPROOFPRINTDATE  INSURANCECERTPRINTDATE  BPRINTINSURANCEPROOF  PRINTINGLANGUAGE  LASTUPDATED          
------------  ----------  ----------  -----------------  -----------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -------------------  -------------  ------  ----------  -----------------------  ----------------------  --------------------  ----------------  -------------------  
2255287412    1431015076  2255287410  2255287411         (null)             SZMZR#31  SGSIT051  2019-12-05   742764  2019-12-05        2019-12-05      MZRFEHLER#0      (null)                SGsit051   Protection#0         (null)         H41206  2019-01-01  (null)                   (null)                  1                     CorresLang#D      2019-12-05 10:59:55  
*/
select * from vista.tikemployerarchive where billnbr='H41206';

-- Update 16.12.2019 (SIT401)
select * from vista.tikheader where vnr='7569171233202'; -- 405784643
/*
TIKHEADID   TIKOWNRID  VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ---------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
3722775705  405784643  7569171233202  MUELLER,PETRA  1980       3           25        SEXCODEZAS#2  BSVLAND#100  67180587311    F                2018-11-28 20:29:12  
*/
select * from vista.tikowner where tikownrid=405784643; -- kpvroleid=399056325

-- working case (TPN Switzerland)
select * from vista.tpvpartner where name='TPN Switzerland GmbH'; -- 2121692687
select * from vista.tikemployerarchive where kpvpartner=2121692687;
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                  ADR2                   ADR3  ADR4         KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
----------  -------  ----------  -----------  --------------------  ---------------------  ----  -----------  --------------  ------------  ---------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ------------------  -------------  --------  ------------  -------------------  
2271215052  QG6063   (null)      BRANCHE#46   TPN Switzerland GmbH  Bahnhofstrasse 98/100        8001 ZÃƒÂ¼rich  4239426634      CHE428802534  ERFASSTCOD#MGAG  RECHTSFORM#H  EADMINCODE#J  1646071200454         190195094608443   1646071200454         619444946607455           2016-03-01  2019-04-30  6dc4c186-49d9-4d3f-af6e-0c291aaee9f2  2121692687  2121692687      2121692735          SONDERFALL#03  963169    MEMBERTYP#AK  2019-06-16 07:24:55  
*/
select * from vista.tikvaikrequest where billno='QG6063'; -- empty


-- 219641 - SG - LDAP User nicht repliziert
select * from vista.tpvpartner where kpvpartid=2168054155;
select * from vista.tpvrole where kpvpartid=2168054155 and croletype='Rolle#MIT';
/*
TPVROLEID   KPVROLEID   KPVPARTID   CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
2245760744  2245760745  2168054155  Rolle#MIT  (null)     (null)       (null)  2019-11-08  9999-12-31  2019-11-08 08:54:22  
*/
select * from vista.tpvemployee where tpvroleid=2245760744;
/*
TPVEMPLID   KPVEMPLID   TPVROLEID   KPVPARTID_TUTOR  CTEAMGROUP  CJOBROLE  SHORTNAME  PHONE          FAX            EMAIL                  DEPARTMENT  DEPARTMENTCHIEF  DIVISION  DIVISIONCHIEF  SECTION  SECTIONCHIEF  TEAM    TEAMLEADER  EMPGROUP  GROUPLEADER  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------  ---------------  ----------  --------  ---------  -------------  -------------  ---------------------  ----------  ---------------  --------  -------------  -------  ------------  ------  ----------  --------  -----------  ----------  ----------  -------------------  
2245760747  2245760748  2245760744  (null)           (null)      (null)    stk        071 282 68 11  071 282 69 12  kai.staeheli@svasg.ch  (null)      (null)           (null)    (null)         (null)   (null)        (null)  (null)      (null)    (null)       2019-11-08  9999-12-31  2019-12-03 17:08:09  
*/
select * from vista.tpvrole where tpvroleid=2245760745;
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and outboundmsg like '%ldapName%' and lastupdated >= '2012-12-01';
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and lastupdated >= '2012-12-01' and outboundmsg like 
'%<ns2:employee>
                <ns2:ldapName>%'; -- working case
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and lastupdated >= '2012-12-01' and outboundmsg like 
'%<ns2:employee>
                <ns2:user%'; -- error case
-- Fall im Ticket (Staeheli):
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and lastupdated >= '2012-11-01' and outboundmsg like '%<ns2:lzPartnerKey>2168054155</ns2:lzPartnerKey>%';
-- 1 replication at 2019-12-03 17:10:44, triggeringObject=EMPLOYEE

-- 220583 - ZH - Fehlermeldung KorrespondenzempfÃƒÂ¤nger
-- 756.1171.1360.02
select * from vista.tpvpartner where personid='7561171136002'; -- 132985661
select * from vista.tpvrole where kpvpartid=132985661; -- RE: 5016945695
select * from vista.tpvrolerel where kpvroleid_source=5016945695 and crelationtype='RoleRelati#KE';
/*
TPVRRELID   KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID   KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT      MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
----------  ----------------  ----------------  ---------  ----------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  ---------------------  ------------------  -----------  -------------------  
5016945714  5016945695        132985663         (null)     5016945715  2499960030      (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2019-12-23  9999-12-31  Correspond#REK      Guten Tag Frau Mathis  (null)              (null)       2019-12-23 16:40:34  
5016945723  5016945695        25061269          (null)     5016945724  32352275        (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2019-12-23  9999-12-31  Correspond#REK      Guten Tag              (null)              (null)       2019-12-23 16:40:34  
5016945729  5016945695        112489497         (null)     5016945730  112489787       (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2019-12-23  9999-12-31  Correspond#REK      Guten Tag              (null)              (null)       2019-12-23 16:40:34  
*/
select * from vista.tpvaddress where kpvadrsid in (2499960030, 32352275, 112489787);
/*
TPVADRSID   KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID   CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          EGID    EWID    
----------  ---------  -------------------  ---------  ----------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  ------  ------  
2499960029  132985661  (null)               607367     2499960030  AddressTyp#ZA  (null)     (null)     AppendixPo#V  80        80             (null)  N       AddressStr#CH  (null)        1900-01-01  9999-12-31  (null)         2016-12-01 08:22:59  (null)  (null)  
32352273    25061253   963169               507021     32352275    AddressTyp#GS  (null)     (null)     AppendixPo#V  41        41             (null)  N       AddressStr#CH  (null)        1900-01-01  9999-12-31  (null)         2018-06-09 08:14:47  (null)  (null)  
112489786   112489495  963169               672457     112489787   AddressTyp#GS                        AppendixPo#V                           (null)  N       AddressStr#CH  (null)        2009-01-01  2011-03-31  (null)         2018-06-09 08:16:34  (null)  (null)  
170348707   112489495  963169               658697     112489787   AddressTyp#GS  (null)     (null)     AppendixPo#V  21        21             (null)  N       AddressStr#CH  (null)        2011-04-01  9999-12-31  (null)         2018-06-09 08:16:34  (null)  (null)  
*/
select * from vista.tpvaddressbasic where kpvadbaid in (607367, 507021, 672457, 658697);
/*
TPVADBAID  KPVADBAID  STREET                 STREETSX  UPPERSTREET            ZIP     CITY        CITYSX  UPPERCITY   CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          UNPRECISE  
---------  ---------  ---------------------  --------  ---------------------  ------  ----------  ------  ----------  ---------  ----------  -------  ----------  ----------  -------------------  ---------  
607364     607367     TÃƒÂ¶sstalstrasse         T234      TÃƒâ€“SSTALSTRASSE         840000  Winterthur  W536    WINTERTHUR  Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:35:27  0          
507017     507021     Schwamendingenstrasse  S553      SCHWAMENDINGENSTRASSE  805000  ZÃƒÂ¼rich      Z620    ZÃƒÅ“RICH      Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:33:32  0          
672452     672457     (null)                 (null)    (null)                 802200  ZÃƒÂ¼rich      Z620    ZÃƒÅ“RICH      Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:36:39  0          
658696     658697     BÃƒÂ¤ndliweg              B534      BÃƒâ€žNDLIWEG              806400  ZÃƒÂ¼rich      Z620    ZÃƒÅ“RICH      Canton#ZH  Country#CH  N        1900-01-01  9999-12-31  2008-10-23 05:36:24  0          
*/
select * from vista.tpvpartner where kpvpartid in (132985661, 25061253, 112489495);
/*
TPVPARTID  KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE    SOCIALSECNR  TITEL   NAME                         NAMESX  UPPERNAME                    FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE   BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE       CLEGALFORM      CSEX    ADDITIONALNAME          UPPERADDITIONALNAME     CCANTON    COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID       CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  RESIDAUTHORTO  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS  TEMP    ISVIC  VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          
---------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  --------------  -----------  ------  ---------------------------  ------  ---------------------------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ----------  -------------  ------------  ----------------  ------------  ---------------  --------------  ------  ----------------------  ----------------------  ---------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  -------------  -----------  --------------  ----------------  --------------------  ------------  ----------------  -------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  -------  ------  -----  ----------  ----------  --------  -------------  -------------------  
132985660  132985661  (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP   63694545116          Mathis                       M320    MATHIS                       Stephanie  S315         STEPHANIE       Mathis    MATHIS         (null)     (null)          NameHyphen#Y   CorresLang#D  1994-02-14  0              Civil stat#L  1994-02-14        Protection#0  (null)           (null)          Sex#W   (null)                  (null)                  (null)     (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#CH    1994-02-14        7561171136002  (null)       (null)          Country#CH        1994-02-14            (null)        (null)            (null)         (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       (null)   N       N      1994-02-14  9999-12-31  (null)    (null)         2019-07-26 15:28:35  
25061251   25061253   (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NNP  (null)       (null)  Sozialzentrum Dorflinde      S242    SOZIALZENTRUM DORFLINDE      (null)     (null)       (null)          (null)    (null)         (null)     (null)          (null)         CorresLang#D  (null)      (null)         (null)        (null)            Protection#0  NNPersonTy#NNP   LegalFormC#OEF  (null)  QT Schwamendingen West  QT SCHWAMENDINGEN WEST  (null)     (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        (null)        (null)            (null)         (null)       (null)          (null)            (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       (null)   N       N      1900-01-01  9999-12-31  (null)    (null)         2017-01-10 14:02:04  
112489494  112489495  (null)           (null)               963169              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NNP  (null)       (null)  Kantonales Steueramt ZÃƒÂ¼rich  K535    KANTONALES STEUERAMT ZÃƒÅ“RICH  (null)     (null)       (null)          (null)    (null)         (null)     (null)          (null)         CorresLang#D  (null)      (null)         (null)        (null)            Protection#0  NNPersonTy#KSTA  LegalFormC#OEF  (null)  (null)                  (null)                  Canton#ZH  (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        (null)        (null)            (null)         (null)       (null)          (null)            (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    (null)        (null)          (null)      (null)       (null)   (null)  N      1900-01-01  9999-12-31  (null)    (null)         2011-04-08 15:25:12  
*/


-- Glitch in Partner-Replication (ZAS-Name) - AndrÃƒÂ©, Mail 06.01.2019
select * from vista.tpvpartner where kpvpartid=1265085; -- personid = 7566492307421
select * from vista.aurupiregister where new_nnss='7566492307421' or old_ahv_or_nnss='7566492307421';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1513327711        7566492307421    7569366893242  2         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2019-12-16 12:00:32  
*/
select * from vista.aurupiregister where old_ahv_or_nnss='7569366893242' or new_nnss='7569366893242';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  --------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1513327711        7566492307421    7569366893242  2         0            ,                     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2019-12-16 12:00:32  
1522761906        7569366893242    7569366893242  0         1            ZWICKY,KURT FRIDOLIN  1         23011960  100            950000    (null)     2              (null)             02111984           (null)         2019-12-16 12:00:32  
1522761907        7569366893242    7569366893242  0         0            ZWICKY,KURT FRIDOLIN  1         23011960  100            950000    (null)     (null)         (null)             (null)             (null)         2019-12-16 12:00:32  
1529861962        99860123114      7569366893242  0         0            ZWICKI,KURT           1         23011960  100            (null)    (null)     (null)         (null)             (null)             (null)         2019-12-16 12:00:32  
1529861963        99860123211      7569366893242  0         0            ZWICKY,KURT FRIDOLIN  1         23011960  100            (null)    (null)     (null)         (null)             (null)             (null)         2019-12-16 12:00:32  
*/


--
SELECT * FROM vista.TSFMQINBOUND WHERE jmstype='BZ.BW-N001' AND INBOUNDMSG LIKE '%1749073%' AND lastupdated > '2020-01-14';
-- ID:414d5120414258313433385320202020879f1d5e21a0722c
SELECT * FROM vista.TSFMQINBOUND WHERE jmstype='BZ.BW-N001' AND jmsmessageid='ID:414d5120414258313433385320202020879f1d5e21a0722c' and lastupdated > '2020-01-14';
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                             JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  ------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
1019906661      0       (null)  JMSTextMessage   BZ.BW-N001  1                0              4            ID:414d5120414258313433385320202020879f1d5e21a0722c  1579075680877  53e0e514-23f8-4b74-a4a9-8b8e56e7a06c  queue:///BZBW.N001.EMPLOYERARCHIVE.NOTIFY  (null)      0               ABX1438S                      1                  svcmqsit      UTF-8                  273               MQSTR           8                26                   20200115         08080083         6c334387-635a-4254-8b9a-9b8ed3c5d657  BE        (null)  BEBW0A01  de                (null)              2.1      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-UpdateEmployerArchiveRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0023/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2">
    <head>
        <senderId>BZ-IK</senderId>
        <initiatedSenderId>BZ-IK</initiatedSenderId>
        <messageID>155f51b3-6bb3-4fda-9918-934608396930</messageID>
        <businessProcessID>6c334387-635a-4254-8b9a-9b8ed3c5d657</businessProcessID>
        <message>
            <type>igs-0023</type>
            <version>2.1</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.61.0</sendingProductVersion>
        </sendingApplication>
        <messageDate>2020-01-15T09:08:01.000+01:00</messageDate>
        <initialMessageDate>2020-01-15T09:08:01.000+01:00</initialMessageDate>
        <eventDate>2020-01-15T09:08:01.000+01:00</eventDate>
        <tenant>BE</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:BWObjectKey>13596630-b546-4b75-a60f-20a18ce43598</ns2:BWObjectKey>
        <ns2:BillNumber>1770405</ns2:BillNumber>
        <ns2:PVPartnerID>1063363</ns2:PVPartnerID>
        <ns2:PVRegisterAddressID>3816338</ns2:PVRegisterAddressID>
        <ns2:PVCorrespondencePartnerID>1063363</ns2:PVCorrespondencePartnerID>
        <ns2:PVCorrespondenceAddressID>7163840</ns2:PVCorrespondenceAddressID>
        <ns2:RegisterCode>MGPBNE</ns2:RegisterCode>
        <ns2:SpecialCaseCode>CODE_04</ns2:SpecialCaseCode>
        <ns2:Township>7068159</ns2:Township>
        <ns2:LegalForm>B</ns2:LegalForm>
        <ns2:MemberCode>AK</ns2:MemberCode>
        <ns2:CodeEAdmin>false</ns2:CodeEAdmin>
        <ns2:ValidFrom>2019-01-01+01:00</ns2:ValidFrom>
        <ns2:ValidTo>9999-12-31+01:00</ns2:ValidTo>
    </ns2:body>
</ns2:IGS-UpdateEmployerArchiveRequest>  2020-01-15 11:24:23  
*/
-- PVPartnerID
select * from vista.tpvpartner where kpvpartid=1063363; -- NP: 7563061724689
-- PVRegisterAddressID
select * from vista.tpvaddress where kpvadrsid=3816338; -- WS
-- PVCorrespondencePartnerID = PVPartnerId
-- PVCorrespondenceAddressID
select * from vista.tpvaddress where kpvadrsid=7163840; -- empty



-- Corinne case: Eintrag im Kurzregister zur Abrechnungsnummer 1749073 kann nicht gespeichert werden, da Parameter  [KPVCORRADDRESS: 3811432] ung\xFCltigen Wert enth\xE4lt.
select * from vista.tsfmqinbound where jmsmessageid='87530f99-5f87-4d6b-a76b-8d9f134c6d52'; -- empty
select * from vista.tsfmqinbound where jmscorrelationid='87530f99-5f87-4d6b-a76b-8d9f134c6d52'; -- empty
select * from vista.tsfmqinbound where businessprocessid='ac5df07f-ba51-4f00-be08-95cc82dfe297';
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                             JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  ------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
1019612088      0       (null)  JMSTextMessage   BZ.BW-N001  1                0              4            ID:414d5120414258313433385320202020879f1d5e219e0b8c  1579074528308  8ba44ceb-730f-4aaf-9a02-34bb92e72f79  queue:///BZBW.N001.EMPLOYERARCHIVE.NOTIFY  (null)      0               ABX1438S                      1                  svcmqsit      UTF-8                  273               MQSTR           8                26                   20200115         07484823         ac5df07f-ba51-4f00-be08-95cc82dfe297  BE        (null)  BEBW0A01  de                (null)              2.1      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-UpdateEmployerArchiveRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0023/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2">
    <head>
        <senderId>BZ-IK</senderId>
        <initiatedSenderId>BZ-IK</initiatedSenderId>
        <messageID>87530f99-5f87-4d6b-a76b-8d9f134c6d52</messageID>
        <businessProcessID>ac5df07f-ba51-4f00-be08-95cc82dfe297</businessProcessID>
        <message>
            <type>igs-0023</type>
            <version>2.1</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.61.0</sendingProductVersion>
        </sendingApplication>
        <messageDate>2020-01-15T08:48:48.000+01:00</messageDate>
        <initialMessageDate>2020-01-15T08:48:48.000+01:00</initialMessageDate>
        <eventDate>2020-01-15T08:48:48.000+01:00</eventDate>
        <tenant>BE</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:BWObjectKey>a1e421b8-f35d-41f4-a1f1-a97fe1125d53</ns2:BWObjectKey>
        <ns2:BillNumber>1749073</ns2:BillNumber>
        <ns2:PVPartnerID>3149090</ns2:PVPartnerID>
        <ns2:PVRegisterAddressID>3964868</ns2:PVRegisterAddressID>
        <ns2:PVCorrespondencePartnerID>3149090</ns2:PVCorrespondencePartnerID>
        <ns2:PVCorrespondenceAddressID>3811432</ns2:PVCorrespondenceAddressID>
        <ns2:RegisterCode>MGPBNE</ns2:RegisterCode>
        <ns2:SpecialCaseCode>CODE_04</ns2:SpecialCaseCode>
        <ns2:Township>7066498</ns2:Township>
        <ns2:LegalForm>B</ns2:LegalForm>
        <ns2:MemberCode>AK</ns2:MemberCode>
        <ns2:CodeEAdmin>false</ns2:CodeEAdmin>
        <ns2:ValidFrom>2019-01-01+01:00</ns2:ValidFrom>
        <ns2:ValidTo>9999-12-31+01:00</ns2:ValidTo>
    </ns2:body>
</ns2:IGS-UpdateEmployerArchiveRequest>  2020-01-15 10:57:51  
*/
-- PVPartnerID
select * from vista.tpvpartner where kpvpartid=3149090; -- NP: 7566556431819
-- PVRegisterAddressID
select * from vista.tpvaddress where kpvadrsid=3964868; -- WS
-- PVCorrespondencePartnerID = PVPartnerId
-- PVCorrespondenceAddressID
select * from vista.tpvaddress where kpvadrsid=3811432; -- empty


-- Corinne Case 2: 1782765, [KPREGISTERADDRESS: 4231653, KPVCORRADDRESS: 4231653]]
SELECT * FROM vista.TSFMQINBOUND WHERE jmstype='BZ.BW-N001' AND INBOUNDMSG LIKE '%<ns2:BillNumber>1782765</ns2:BillNumber>%' AND lastupdated >= '2020-01-15';
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                             JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  ------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
1020069759      0       (null)  JMSTextMessage   BZ.BW-N001  1                0              4            ID:414d5120414258313433385320202020879f1d5e21a1d12c  1579076317746  ab2691a6-cde5-4957-be9f-562b97e38364  queue:///BZBW.N001.EMPLOYERARCHIVE.NOTIFY  (null)      0               ABX1438S                      1                  svcmqsit      UTF-8                  273               MQSTR           8                26                   20200115         08183774         49efb6f5-1c70-4f20-ae61-e6f22ea14fcd  BE        (null)  BEBW0A01  de                (null)              2.1      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:IGS-UpdateEmployerArchiveRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0023/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0007/2">
    <head>
        <senderId>BZ-IK</senderId>
        <initiatedSenderId>BZ-IK</initiatedSenderId>
        <messageID>b243a19a-e582-4f61-a541-f5026606bd42</messageID>
        <businessProcessID>49efb6f5-1c70-4f20-ae61-e6f22ea14fcd</businessProcessID>
        <message>
            <type>igs-0023</type>
            <version>2.1</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.61.0</sendingProductVersion>
        </sendingApplication>
        <messageDate>2020-01-15T09:18:38.000+01:00</messageDate>
        <initialMessageDate>2020-01-15T09:18:38.000+01:00</initialMessageDate>
        <eventDate>2020-01-15T09:18:38.000+01:00</eventDate>
        <tenant>BE</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns2:body>
        <ns2:BWObjectKey>a5cfebbc-ce59-4008-9c02-8c7a7e04bcc2</ns2:BWObjectKey>
        <ns2:BillNumber>1782765</ns2:BillNumber>
        <ns2:UID>CHE224243362</ns2:UID>
        <ns2:PVPartnerID>2899832</ns2:PVPartnerID>
        <ns2:PVRegisterAddressID>4231653</ns2:PVRegisterAddressID>
        <ns2:PVCorrespondencePartnerID>2899832</ns2:PVCorrespondencePartnerID>
        <ns2:PVCorrespondenceAddressID>4231653</ns2:PVCorrespondenceAddressID>
        <ns2:BusinessSectorCode>96</ns2:BusinessSectorCode>
        <ns2:RegisterCode>MGPBSE</ns2:RegisterCode>
        <ns2:SpecialCaseCode>CODE_02</ns2:SpecialCaseCode>
        <ns2:Township>7066493</ns2:Township>
        <ns2:LegalForm>A</ns2:LegalForm>
        <ns2:MemberCode>AK</ns2:MemberCode>
        <ns2:CodeEAdmin>false</ns2:CodeEAdmin>
        <ns2:ValidFrom>2019-09-01+02:00</ns2:ValidFrom>
        <ns2:ValidTo>9999-12-31+01:00</ns2:ValidTo>
    </ns2:body>
</ns2:IGS-UpdateEmployerArchiveRequest>  2020-01-15 11:41:29  
*/
-- PVPartnerID
select * from vista.tpvpartner where kpvpartid=2899832; -- NP: 7564753265299
select * from vista.tpvaddress where kpvpartid=2899832;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1       APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY                         LASTUPDATED          EGID    EWID    
---------  ---------  -------------------  ---------  ---------  -------------  --------------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  ------------------------------------  -------------------  ------  ------  
114772846  2899832    7066363              100308094  4218903    AddressTyp#GS  Coiffeursalon   (null)     AppendixPo#V  24        24             (null)  N       AddressStr#CH  (null)        2010-02-05  2019-08-31  18cc512f-fa5b-4da7-9cd8-8df37f0aa2c0  2019-12-17 15:30:56  (null)  (null)  
114772847  2899832    7060216              100330470  4218903    AddressTyp#GS  Coiffeur Vlora  (null)     AppendixPo#V  25        25             (null)  N       AddressStr#CH  (null)        2019-09-01  9999-12-31  9fc254a4-86d6-4bae-8c56-2ea8ea1f15a3  2019-12-17 15:30:56  (null)  (null)  
*/
-- PVRegisterAddressID
select * from vista.tpvaddress where kpvadrsid=4231653; -- empty
-- PVCorrespondencePartnerID = PVPartnerId
-- PVCorrespondenceAddressID
select * from vista.tpvaddress where kpvadrsid=4231653; -- empty


--
select count(*) from vista.tpvpartner where clegaltype like '%#POLG' and ccanton='Canton#ZH'; -- 322
select count(*) from vista.tpvpartner where clegaltype like '%#POLG' and ccanton <> 'Canton#ZH'; -- 2061
select count(*) from vista.tpvregionmunauth; -- 2235
select count(*) from vista.tpvregionmunauth where validfrom > current date; -- Future: 0
select count(*) from vista.tpvregionmunauth where validto < current date; -- Terminated: 1
select count(*) from vista.tpvregionmunauth where validfrom < current date and validto > current date; -- Normal case: 2234
select count(*) from vista.tpvpartner where clegaltype like '%#POLG' and validfrom > current date; -- Future: 0 (however, this number changes for pending fusions)
select count(*) from vista.tpvpartner where clegaltype like '%#POLG' and validto < current date; -- 161
select count(*) from vista.tpvpartner p1 where p1.clegaltype like '%#POLG' and p1.validto < current date 
and exists (select 1 from vista.tpvpartner p2 where p2.kpvpartid = p1.kpvpartid and p2.tpvpartid <> p1.tpvpartid); -- mutated POLGs: 160

-- PV.2019.65077 Ã¢â‚¬â€œ CM-Updates - Franz. ÃƒÅ“bersetzungen
select c.code_id, c.shortcode, c.value, d.short_descript as d_short, d.medium_descript as d_medium, f.short_descript as f_short, f.medium_descript as f_medium from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcode_descr f on (f.codetypeno = c.codetypeno and f.codeno = c.codeno and f.language=2)
where c.code_id like 'Salu%'
order by c.value;

select distinct f.REC_IDE, f.HDR_IDE, f.PROD_STATE, f.CREATETIME, f.DESCRIPTION
from dope.dop_fd f
where date(f.CREATETIME) >'2017-11-01' and f.HDR_IDE like '%IKPK%';

select * from vista.aurupiregister where statuscd = 3; -- 7568301994648
select * from vista.aurupiregister where new_nnss='7568301994648' or old_ahv_or_nnss='7568301994648';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1623052635        7568301994648    0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
*/
select * from vista.aurupiregister where statuscd = 3; -- 7566626652540
select * from vista.aurupiregister where new_nnss='7566626652540' or old_ahv_or_nnss='7566626652540';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1617538028        7566626652540    0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
*/
select * from vista.aurupiregister where statuscd = 2; -- 7562556283793
select * from vista.aurupiregister where new_nnss='7562556283793' or old_ahv_or_nnss='7562556283793';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                            GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ------------------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1604134764        7562556283793    7562556283793  0         1            TORNAY,THERESE JEANNETTE        2         06081929  100            950000    05012014   3              (null)             22102009           (null)         2020-01-11 20:15:42  
1604134765        7562556283793    7562556283793  0         0            TORNAY,THERESE JEANNETTE        2         06081929  100            950000    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
1606318138        7563219357059    7562556283793  2         0            ,                               0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
1606318139        7563219357059    7562556283793  0         0            TORNAY,JEANNINE                 2         06081929  999            800000    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
1631662759        88929737118      7562556283793  0         0            TORNAY-LOVEY,THERESE JEANNETTE  2         06081929  100            (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
*/
select * from vista.aurupiregister where statuscd = 2; -- 7561543377958
select * from vista.aurupiregister where new_nnss='7561543377958' or old_ahv_or_nnss='7561543377958';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                            GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ------------------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1594192541        70610388114      7561543377958  0         0            PELLANDA,ANTON                  1         26091910  100            (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
1600707737        7561514559581    7561543377958  2         0            ,                               0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2020-01-11 20:15:42  
1600802306        7561543377958    7561543377958  0         1            PELLANDA,GIOVAN ANTONIO MATTEO  1         26091910  100            950000    19042006   3              (null)             16042006           (null)         2020-01-11 20:15:42  
*/
select * from vista.aurupiregister where statuscd = 2 and actualitycd=1; -- empty

select count(*) from vista.aurupiregister where new_nnss='0' or old_ahv_or_nnss='0';


-- SIT417 - SEDEX / Defect 24306 - IK.2019.69169 SEDEX - IKJB10401 erstellt falsche attachment Filename und nur immer eines
select * from vista.tzaxmlsdxrecord; -- where tzaxmlsdxrecordid=2255902814;
select * from vista.tzaxmlsdxrecord where sdxxmlfilename like 'lz_ik2050%';
select * from vista.tzasedexattachment;
select * from vista.tbcfileentry;
select * from vista.tbcfiledata;

select * from vista.tikemployerarchive;
select * from vista.tikbooking;
select * from vista.tpvrole order by lastupdated desc;

select pid1.* from vista.tpvelarpid pid1
left join vista.tpvelarpid pid2 on (pid2.kpvpartid = pid1.kpvpartid and pid2.elarpid <> pid1.elarpid)
where pid2.elarpid is not null;

select * from vista.tpvpartner where clegaltype like '%#POLG'; -- clegalform immer NULL

-- OM-Log
select count(*) from vista.tommessage where ccontextid='CONTEXT#IK' and subcontextid='IKJVZAB201' and cmessageseverityid='MSGLEVEL#ERROR' and messagetimestamp > '2011-09-17 20:00:00';


-- 24708 - PV-Schutzcode wird bei autom. IK-ErÃƒÂ¶ffnung ÃƒÂ¼berschrieben (resp. zurÃƒÂ¼ckgesetzt)
-- Getestet mit P.12.51.002 / SIT401 / ZH / 06.01.2020 / KAN
select kpvpartid, tpvpartid, name, personid, cconfidlevel, lastupdated from vista.tpvpartner where personid='7567400013687';
/*
KPVPARTID   TPVPARTID   NAME    PERSONID       CCONFIDLEVEL  LASTUPDATED          
----------  ----------  ------  -------------  ------------  -------------------  
4727665429  4727665428  COZZIO  7567400013687  Protection#0  2020-02-06 10:06:04  
*/
select * from vista.jpvrole where kpvpartid=4727665429 and croletype='Rolle#IK';
/*
TPVROLEID   KPVROLEID   KPVPARTID   CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM           OPERATION  
----------  ----------  ----------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ----------------  ---------  
4727666116  4727666117  4727665429  Rolle#IK   (null)     (null)       (null)  2020-02-06  9999-12-31  2020-02-06 09:50:16  2020-02-06 09:50:16  zhsit048     IK:LZ.IK-I001-V2  I          
*/
select kpvpartid, tpvpartid, name, personid, cconfidlevel, change_user, program, change_date from vista.jpvpartner where kpvpartid='4727665429';
/*
KPVPARTID   TPVPARTID   NAME    PERSONID       CCONFIDLEVEL  CHANGE_USER  PROGRAM                   CHANGE_DATE          
----------  ----------  ------  -------------  ------------  -----------  ------------------------  -------------------  
4727665429  4727665428  Cozzi   7567400013687  Protection#5  ZHsit048     PV:PV-Dlg-201 Person      2020-02-06 09:42:08  
4727665429  4727665428  Cozzi   7567400013687  Protection#5  ZHIK0A01     IK:IKJMEBB102:4727667257  2020-02-06 10:06:04  
4727665429  4727665428  COZZIO  7567400013687  Protection#5  ZHIK0A01     IK:IKJMEBB102:4727667257  2020-02-06 10:06:04  
*/
select * from vista.tsfmqinbound where jmstype='LZ.IK-I001' and lastupdated > '2020-02-06 09:42:16' and lastupdated < '2020-02-06 09:52:16';
/*
TSFMQINBOUNDID  STATUS  REASON  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                          JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID                     TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  INBOUNDMSG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    LASTUPDATED          
--------------  ------  ------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  --------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  ------------------------------------  --------  ------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
4727666111      0       (null)  JMSTextMessage   LZ.IK-I001  2                0              4            ID:414d5120545353313430315320202020543e265e2596a503  1580979015760  1b94b8ff-1798-41c3-914e-2dcf7b285313  queue:///BZBW.LZIK.I001.BOOKING.CREATE  (null)      0               TSS1401S                      1                  svcmqsit      UTF-8                  273               MQSTR           8                26                   20200206         08501578         3f75c4cb-3e77-422a-ab81-72b3e32cea1f  ZH        (null)  zhsit048  de                (null)              2.1      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:IGS-CreateBookingRequest xmlns="https://igs-gmbh.ch/xmlns/igs-0006/2" xmlns:ns2="https://igs-gmbh.ch/xmlns/igs-0015/2" xmlns:ns4="https://igs-gmbh.ch/xmlns/igs-0007/2" xmlns:ns3="https://igs-gmbh.ch/xmlns/igs-0022/2">
    <head>
        <senderId>BZ-IK</senderId>
        <initiatedSenderId>BZ-IK</initiatedSenderId>
        <messageID>a8af78fa-4095-4a50-ac40-f5e41f745d0b</messageID>
        <businessProcessID>3f75c4cb-3e77-422a-ab81-72b3e32cea1f</businessProcessID>
        <message>
            <type>igs-0022</type>
            <version>2.1</version>
        </message>
        <sendingApplication>
            <sendingProduct>NIL</sendingProduct>
            <sendingProductVersion>3.63.0</sendingProductVersion>
        </sendingApplication>
        <messageDate>2020-02-06T09:50:16.000+01:00</messageDate>
        <initialMessageDate>2020-02-06T09:50:16.000+01:00</initialMessageDate>
        <eventDate>2020-02-06T09:50:16.000+01:00</eventDate>
        <tenant>ZH</tenant>
        <languageCode>de</languageCode>
    </head>
    <ns3:body>
        <ns3:Booking>
            <ns2:InsuranceNumber>7567400013687</ns2:InsuranceNumber>
            <ns2:BillNumber>EE7344</ns2:BillNumber>
            <ns2:CodeStorno>0</ns2:CodeStorno>
            <ns2:CodeContributionType>1</ns2:CodeContributionType>
            <ns2:ContributionPeriod>
                <ns2:BeginMonth>1</ns2:BeginMonth>
                <ns2:EndMonth>12</ns2:EndMonth>
            </ns2:ContributionPeriod>
            <ns2:ContributionYear>2018+01:00</ns2:ContributionYear>
            <ns2:Income>3500.00</ns2:Income>
            <ns2:Branch>00</ns2:Branch>
            <ns2:TownshipBFS>261</ns2:TownshipBFS>
            <ns2:AccountType>IK</ns2:AccountType>
            <ns2:BookedBy>zhsit048</ns2:BookedBy>
            <ns2:BookingDate>2020-02-06T09:50:16.000+01:00</ns2:BookingDate>
            <ns2:FlagSplitting>false</ns2:FlagSplitting>
            <ns2:OIDBookingBW>
                <ns2:SalaryList>
                    <ns2:SalaryListOID>c8e49d61-b710-4698-88c7-15f525fd0cda</ns2:SalaryListOID>
                    <ns2:EntryOID>5f93ebd2-adbd-4116-bee5-5ce1cbb5f852</ns2:EntryOID>
                </ns2:SalaryList>
            </ns2:OIDBookingBW>
        </ns3:Booking>
        <ns3:BusinessProcessID xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1f3be674-7b29-4315-a573-b32e0943fb5b</ns3:BusinessProcessID>
    </ns3:body>
</ns3:IGS-CreateBookingRequest>  2020-02-06 09:50:16  
*/
select * from vista.tikinsurancerequest where customer=4727666117; -- empty
select * from vista.tikvaikrequest where kpvroleid=4727666117;
/*
TIKVAIKREQID  KPVROLEID   TIKVIOOID   DELIVERYADDRESSIK  DELIVERYADDRESSPK  CSZ       AKNOTICE           REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CPENDPROTECTIONCODE  BHASALREADYIK  BILLNO  ENTRYDATE  INSURANCEPROOFPRINTDATE  INSURANCECERTPRINTDATE  BPRINTINSURANCEPROOF  PRINTINGLANGUAGE  LASTUPDATED          
------------  ----------  ----------  -----------------  -----------------  --------  -----------------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -------------------  -------------  ------  ---------  -----------------------  ----------------------  --------------------  ----------------  -------------------  
4727666122    4727666117  4727666115  (null)             (null)             SZMZR#61  AUT. IKEROEFFNUNG  2020-02-06   662370  (null)            2020-02-06      MZRFEHLER#0      (null)                zhsit048   Protection#0         (null)         (null)  (null)     (null)                   (null)                  0                     CorresLang#D      2020-02-06 10:06:04  
*/
select tikvaikreqid, kpvroleid, csz, aknotice, cpendprotectioncode, change_date, program, change_user from vista.jikvaikrequest where kpvroleid=4727666117;
/*
TIKVAIKREQID  KPVROLEID   CSZ       AKNOTICE           CPENDPROTECTIONCODE  CHANGE_DATE          PROGRAM                   CHANGE_USER  
------------  ----------  --------  -----------------  -------------------  -------------------  ------------------------  -----------  
4727666122    4727666117  SZMZR#61  AUT. IKEROEFFNUNG  Protection#0         2020-02-06 09:50:16  IK:LZ.IK-I001-V2          zhsit048     
4727666122    4727666117  SZMZR#61  AUT. IKEROEFFNUNG  Protection#0         2020-02-06 10:06:04  IK:IKJMEBB102:4727667257  ZHIK0A01     
*/

-- PV.2020.71665_Epic_Spezifikation_Fusionierte AKs_v01
select * from vista.tpvpartner;

-- 
select * from migration.tdmcsuserdata; -- SIT64: 342 / SIT63: 155
select * from migration.tdmpvemployee; -- SIT64: 19 / SIT63: 343
select * from vista.tpvemployee; -- SIT64: 19 / SIT63: 343

-- 224955 - SZ - PVJMAPAI
select * from vista.tpvpartner where kpvpartid=65694548; -- empty
select * from vista.tpvpartner where kpvpartid=689295269; -- empty
select * from vista.tpvpartnerreplication where tpvpartrepid in (65694548, 689295269); -- empty
select * from vista.tpvpartnerreplication where kpvpartid in (65694548, 689295269); -- empty
select * from vista.tpvpartnerreplication where ctargetappl='BusinessAp#AI' and cstatus <> 'RepState#PROCESSED';
select * from vista.taireplication;

-- Temp999


-- WI Error bei IKJB11107 / Sedex KOAU

select kpvpartid, name, additionalname, clegaltype, ccanton, bfsmunitipalnr, munauthornr, lastupdated from vista.tpvpartner where clegaltype='NNPersonTy#POLG';


-- Epic 25900: [iChange] PV-Replikation: GÃ¼ltigkeit des Zivilstandes nach Todesfall generiert falsches .xml (PV.2020.75802)
-- Case 1 (Case in Defect)
select kpvpartid, tpvpartid, deathdate, ccivilstatus, civilstatussince, cseparation, validfrom, validto, extpartnerkey 
from vista.tpvpartner where kpvpartid=1300028 order by validfrom asc;
/*
KPVPARTID  TPVPARTID  DEATHDATE   CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     EXTPARTNERKEY                         
---------  ---------  ----------  ------------  ----------------  ------------  ----------  ----------  ------------------------------------  
1300028    109565729  2018-09-11  Civil stat#L  1951-12-31        (null)        1951-12-31  1972-05-05  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565732  2018-09-11  Civil stat#H  1972-05-06        Separation#U  1972-05-06  1982-01-13  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565738  2018-09-11  Civil stat#S  1982-01-14        (null)        1982-01-14  1985-09-25  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565742  2018-09-11  Civil stat#H  1985-09-26        Separation#U  1985-09-26  2003-10-09  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565744  2018-09-11  Civil stat#S  2003-10-10        (null)        2003-10-10  2008-12-23  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565746  2018-09-11  Civil stat#S  2003-10-10        (null)        2008-12-24  2011-04-13  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
1300028    109565753  2018-09-11  Civil stat#S  2003-10-10        (null)        2011-04-14  9999-12-31  f32ae361-3136-2dcf-e030-11ac0b0b02f2  
*/
select * from vista.tpvfamilyrel where kpvpartid_source=1098663;
/*
TPVFRELID  KPVPARTID_SOURCE  KPVPARTID_TARGET  CRELATIONTYPE  RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ----------------  ----------------  -------------  -------------  -----------  -------------------  
114846108  1098663           1300028           FamilyRela#EP  1985-09-26     2003-10-09   2020-02-28 21:46:13  
114918453  1098663           1295608           FamilyRela#EP  1979-11-23     1985-01-09   2020-02-28 21:48:26 
*/
select kpvpartid, tpvpartid, deathdate, ccivilstatus, civilstatussince, cseparation, validfrom, validto, extpartnerkey from vista.tpvpartner where kpvpartid=1098663;
/*
KPVPARTID  TPVPARTID  DEATHDATE  CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     EXTPARTNERKEY                         
---------  ---------  ---------  ------------  ----------------  ------------  ----------  ----------  ------------------------------------  
1098663    109570669  (null)     Civil stat#L  1955-02-21        (null)        1955-02-21  1979-11-22  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
1098663    109570670  (null)     Civil stat#H  1979-11-23        Separation#U  1979-11-23  1985-01-09  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
1098663    109570671  (null)     Civil stat#S  1985-01-10        (null)        1985-01-10  1985-09-25  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
1098663    109570673  (null)     Civil stat#H  1985-09-26        Separation#U  1985-09-26  2003-10-09  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
1098663    109570676  (null)     Civil stat#S  2003-10-10        (null)        2003-10-10  2008-12-03  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
1098663    109570679  (null)     Civil stat#S  2003-10-10        (null)        2008-12-04  9999-12-31  f32ae361-3275-2dcf-e030-11ac0b0b02f2  
*/
select kpvpartid, tpvpartid, deathdate, ccivilstatus, civilstatussince, cseparation, validfrom, validto, extpartnerkey 
from vista.tpvpartner where kpvpartid=1295608 order by validfrom;
/*
KPVPARTID  TPVPARTID  DEATHDATE  CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     EXTPARTNERKEY                         
---------  ---------  ---------  ------------  ----------------  ------------  ----------  ----------  ------------------------------------  
1295608    109572746  (null)     Civil stat#L  1956-03-06        (null)        1956-03-06  1979-11-22  f32ae361-330d-2dcf-e030-11ac0b0b02f2  
1295608    109572747  (null)     Civil stat#H  1979-11-23        Separation#U  1979-11-23  1985-01-09  f32ae361-330d-2dcf-e030-11ac0b0b02f2  
1295608    109572751  (null)     Civil stat#S  1985-01-10        (null)        1985-01-10  2008-11-16  f32ae361-330d-2dcf-e030-11ac0b0b02f2  
1295608    109572752  (null)     Civil stat#S  1985-01-10        (null)        2008-11-17  9999-12-31  f32ae361-330d-2dcf-e030-11ac0b0b02f2  
*/
select kpvpartid, tpvpartid, deathdate, ccivilstatus, civilstatussince, cseparation, validfrom, validto, extpartnerkey 
from vista.tpvpartner where kpvpartid=3172155 order by validfrom;
/*
KPVPARTID  TPVPARTID  DEATHDATE   CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     EXTPARTNERKEY                         
---------  ---------  ----------  ------------  ----------------  ------------  ----------  ----------  ------------------------------------  
3172155    106360875  2018-06-09  Civil stat#L  1945-11-28        (null)        1945-11-28  1972-05-05  cf6f8819-c34b-4763-8335-7c037fde6091  
3172155    106360879  2018-06-09  Civil stat#H  1972-05-06        Separation#U  1972-05-06  1982-01-13  cf6f8819-c34b-4763-8335-7c037fde6091  
3172155    106360883  2018-06-09  Civil stat#U  (null)            (null)        1982-01-14  1995-04-20  cf6f8819-c34b-4763-8335-7c037fde6091  
3172155    106360885  2018-06-09  Civil stat#H  1995-04-21        Separation#U  1995-04-21  2008-09-03  cf6f8819-c34b-4763-8335-7c037fde6091  
3172155    106360887  2018-06-09  Civil stat#H  1995-04-21        Separation#U  2008-09-04  9999-12-31  cf6f8819-c34b-4763-8335-7c037fde6091   
*/

select * from vista.tpvfamilyrel f where f.kpvpartid_source in (1098663, 1300028, 3172155, 1295608) 
or f.kpvpartid_target in (1098663, 1300028, 3172155, 1295608) and crelationtype='FamilyRela#EP' order by relationbegin;
/*
TPVFRELID  KPVPARTID_SOURCE  KPVPARTID_TARGET  CRELATIONTYPE  RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ----------------  ----------------  -------------  -------------  -----------  -------------------  
114925218  1300028           3172155           FamilyRela#EP  1972-05-06     1982-01-13   2020-02-28 21:48:39  
114918453  1098663           1295608           FamilyRela#EP  1979-11-23     1985-01-09   2020-02-28 21:48:26  
114846108  1098663           1300028           FamilyRela#EP  1985-09-26     2003-10-09   2020-02-28 21:46:13  
*/

-- Affected cases:
select count(distinct kpvpartid) as cnt_s from vista.tpvpartner where deathdate is not null and ccivilstatus='Civil stat#S'; -- AIT101: 10 / SIT440: 22191

-- Repli-Table
delete from vista.tsfmqoutbound where jmstype='BZ.PV-I003';
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqoutbound order by lastupdated desc;
select * from vista.tsfmqinbound order by lastupdated desc;

-- Case 2: AndrÃ© ("Komischkeit ZivilstÃ¤nde") --> kpvpartid = 1089861
select * from vista.tpvfamilyrel where kpvpartid_source=1089861 or kpvpartid_target=1089861 and crelationtype='FamilyRela#EP'; 
/*
TPVFRELID  KPVPARTID_SOURCE  KPVPARTID_TARGET  CRELATIONTYPE  RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ----------------  ----------------  -------------  -------------  -----------  -------------------  
114766425  1047955           1089861           FamilyRela#EP  1982-12-09     1989-12-20   2020-02-28 21:43:41  
114779819  1089861           1089870           FamilyRela#EP  1995-11-03     1998-05-08   2020-02-28 21:44:07
*/
select kpvpartid, tpvpartid, deathdate, ccivilstatus, civilstatussince, cseparation, validfrom, validto, extpartnerkey 
from vista.tpvpartner where kpvpartid=1089861 order by validfrom asc;
/*
KPVPARTID  TPVPARTID  DEATHDATE   CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     EXTPARTNERKEY                         
---------  ---------  ----------  ------------  ----------------  ------------  ----------  ----------  ------------------------------------  
1089861    109481454  2013-05-29  Civil stat#L  1957-05-31        (null)        1957-05-31  1982-12-08  36c4064f-ebf3-848c-e040-11ac0b0b572c  
1089861    109481457  2013-05-29  Civil stat#H  1982-12-09        Separation#U  1982-12-09  1989-12-20  36c4064f-ebf3-848c-e040-11ac0b0b572c  
1089861    109481462  2013-05-29  Civil stat#S  1989-12-21        (null)        1989-12-21  1995-11-02  36c4064f-ebf3-848c-e040-11ac0b0b572c  
1089861    109481465  2013-05-29  Civil stat#H  1995-11-03        Separation#U  1995-11-03  1998-05-08  36c4064f-ebf3-848c-e040-11ac0b0b572c  
1089861    109481466  2013-05-29  Civil stat#S  1998-05-09        (null)        1998-05-09  2008-10-20  36c4064f-ebf3-848c-e040-11ac0b0b572c  
1089861    109481467  2013-05-29  Civil stat#S  1998-05-09        (null)        2008-10-21  9999-12-31  36c4064f-ebf3-848c-e040-11ac0b0b572c  
*/

-- Repli-Table
--delete from vista.tsfmqoutbound where jmstype='BZ.PV-I003';
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' order by lastupdated desc;


-- Ticket Cristina:
select * from VISTA.TPVPARTNER where KPVPARTID = 1814713 and CPARTNERTYPE ='PartnerTyp#NP';
select * from VISTA.TIKCOLLECTION where TIKDELADDRESSID = '5094016989';
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE  CSZ       VNR            VNRNAME                      VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE  ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          
----------  ---------  ----------  ----------  ----------  --------  --------  -------------  ---------------------------  -------------  -----------  -----------  ------------  ----------------  ---------  -------------------  ---------  ------------------  --------  ---------------  -------------------  
5128982807  407376247  2020-02-06  1           0           ZH322     SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2020-02-06    (null)            (null)     VDR3714210042764364  (null)     N                   N         5094016989       2020-02-14 07:54:48  
*/
select * from VISTA.JIKCOLLECTION where TIKDELADDRESSID = '5094016989';
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE  CSZ       VNR            VNRNAME                      VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE  ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                      OPERATION  
----------  ---------  ----------  ----------  ----------  --------  --------  -------------  ---------------------------  -------------  -----------  -----------  ------------  ----------------  ---------  -------------------  ---------  ------------------  --------  ---------------  -------------------  -------------------  -----------  -------------------------------------------  ---------  
5128982807  407376247  2020-02-06  1           0           ZH322     SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2020-02-06    (null)            (null)     (null)               (null)     N                   J         5094016989       2020-02-07 20:27:31  2020-02-07 20:27:31  ZHIK0A01     IK:IKJB11101:5128978991                      I          
5128982807  407376247  2020-02-06  1           0           ZH322     SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2020-02-06    (null)            (null)     (null)               (null)     N                   J         5094016989       2020-02-07 20:27:31  2020-02-07 20:27:31  ZHIK0A01     IK:IKJB11101:5128978991                      U          
5128982807  407376247  2020-02-06  1           0           ZH322     SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2020-02-06    (null)            (null)     VDR3714210042764364  (null)     N                   J         5094016989       2020-02-07 20:27:31  2020-02-14 07:54:48  ZH208        IK:APP129_IK-Dlg-304_Manage_IK_Collection_e  U          
*/
select * from vista.jikzikrequest where TIKDELADDRESSID = '5094016989';
/*
TIKZIKREQID  KPVROLEID  CORRESPONCEADDRESSID  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CLOSINGDATE  CRESIDANCECODE  CCODELA  VNRLA   VNRLANAME  VISTADOCREF          DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                      OPERATION  
-----------  ---------  --------------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -----------  --------------  -------  ------  ---------  -------------------  ------------------  --------  ---------------  -------------------  -------------------  -----------  -------------------------------------------  ---------  
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 09:08:30  2020-01-27 09:08:30  ZH791        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  I          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 09:08:30  2020-01-27 16:01:41  ZHIK0A01     IK:IKJB10101D:5094810044                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-01-27        (null)          MZRFEHLER#-2     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 16:01:41  2020-01-28 20:27:31  ZHIK0A01     IK:IKJMEBB102:5102148698                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-01-27        2020-01-27      MZRFEHLER#4      (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-28 20:27:31  2020-02-19 14:43:49  ZH208        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 14:43:49  2020-02-19 16:01:06  ZHIK0A01     IK:IKJB10101D:5154350421                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-02-19        (null)          MZRFEHLER#-2     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 16:01:06  2020-02-19 22:10:10  ZHIK0A01     IK:IKJMEBB102:5154775392                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-02-19        2020-02-19      MZRFEHLER#4      (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 22:10:10  2020-03-25 06:50:46  ZH208        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-03-25 06:50:46  2020-03-25 16:00:40  ZHIK0A01     IK:IKJB10101D:5236017677                     U          
*/
select * from vista.tpvrole where kpvroleid=385900367; -- 1814713
select * from vista.tpvpartner where kpvpartid=1814713;
/*
TPVPARTID  KPVPARTID  KPVPARTID_COURT  KPVPARTID_REDUNDANZ  KPVPARTID_MUNAUTOR  KPVPARTID_HEIRREPRESENT  KPVPARTID_BEQUEATHER  KPVPARTID_TAXDOMICILE  KPVPARTID_AHVBRANCHNR  KPVPARTID_OFFICEOPERATIONNR  KPVPARTID_BANKRUPTCY  CPARTNERTYPE   SOCIALSECNR  TITEL  NAME  NAMESX  UPPERNAME  FIRSTNAME  FIRSTNAMESX  UPPERFIRSTNAME  LASTNAME  UPPERLASTNAME  BIRTHNAME  UPPERBIRTHNAME  CNAMESEQUENCE  CLANGUAGE     BIRTHDATE   BIRTHDATEPREC  CCIVILSTATUS  CIVILSTATUSSINCE  CCONFIDLEVEL  CLEGALTYPE  CLEGALFORM  CSEX   ADDITIONALNAME  UPPERADDITIONALNAME  CCANTON  COMPANYNR  AHVBRANCHNR  CAHVCHIEFSALUT  AHVCHIEFFIRSTNAME  AHVCHIEFNAME  AHVCHIEFSINCE  CAHVDEPUTYSALUT  AHVDEPUTYFIRSTNAME  AHVDEPUTYNAME  AHVDEPUTYSINCE  COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CCOMPFUNDTYPE  CCOMPFUNDFAKTYPE  COMPFUNDFUSIONNR  COMPFUNDFUBRANR  OFFICEOPERATIONNR  IVOFFICENR  KKABSVNR  MUNAUTHORNR  CMUNAUTHORCANTON  CMUNAUTHORFLG  CINSURANCETYPE  INSURANCESUVANR  AGENCYNUMBER  CCITIZENSHIP  CITIZENSHIPSINCE  PERSONID       CSEPARATION  SEPARATIONDATE  CCOUNTRYOFLIVING  COUNTRYOFLIVINGSINCE  CRESIDAUTHOR  RESIDAUTHORSINCE  RESIDAUTHORTO  DEATHDATE  CTAXCOUNTRY  CTAXCANTON  TAXREGNR  CTAXATSOURCE  BFSMUNITIPALNR  CCOURTTYPE  CCLERKALLOC  REMARKS  TEMP  ISVIC  VALIDFROM   VALIDTO     TEMP9999  EXTPARTNERKEY  LASTUPDATED          
---------  ---------  ---------------  -------------------  ------------------  -----------------------  --------------------  ---------------------  ---------------------  ---------------------------  --------------------  -------------  -----------  -----  ----  ------  ---------  ---------  -----------  --------------  --------  -------------  ---------  --------------  -------------  ------------  ----------  -------------  ------------  ----------------  ------------  ----------  ----------  -----  --------------  -------------------  -------  ---------  -----------  --------------  -----------------  ------------  -------------  ---------------  ------------------  -------------  --------------  ----------  ----------------  ------------  -------------  ----------------  ----------------  ---------------  -----------------  ----------  --------  -----------  ----------------  -------------  --------------  ---------------  ------------  ------------  ----------------  -------------  -----------  --------------  ----------------  --------------------  ------------  ----------------  -------------  ---------  -----------  ----------  --------  ------------  --------------  ----------  -----------  -------  ----  -----  ----------  ----------  --------  -------------  -------------------  
1814712    1814713    (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  (null)              Ilon  I450    ILON       Catharina  C365         CATHARINA       Ilon      ILON           (null)     (null)          NameHyphen#Y   CorresLang#D  1970-06-14  0              Civil stat#L  1970-06-14        Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#SE    (null)            (null)         (null)       (null)          (null)            (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    Decision#N    (null)          (null)      (null)       (null)   N     N      1970-06-14  1997-12-31  (null)    (null)         2008-10-23 05:54:21  
1814770    1814713    (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  50070676157         Ilon  I450    ILON       Catharina  C365         CATHARINA       Ilon      ILON           (null)     (null)          NameHyphen#Y   CorresLang#D  1970-06-14  0              Civil stat#L  1970-06-14        Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#SE    (null)            (null)         (null)       (null)          Country#CH        (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    Decision#N    (null)          (null)      (null)       (null)   N     N      1998-01-01  2004-12-31  (null)    (null)         2008-10-23 05:54:21  
1814808    1814713    (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  50070676157         Ilon  I450    ILON       Catharina  C365         CATHARINA       Ilon      ILON           (null)     (null)          NameHyphen#Y   CorresLang#D  1970-06-14  0              Civil stat#L  1970-06-14        Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#SE    (null)            (null)         (null)       (null)          Country#CH        (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    Decision#N    (null)          (null)      (null)       (null)   N     N      2005-01-01  2007-12-31  (null)    (null)         2008-10-23 05:54:21  
1814849    1814713    (null)           (null)               (null)              (null)                   (null)                (null)                 (null)                 (null)                       (null)                PartnerTyp#NP  50070676157         Ilon  I450    ILON       Catharina  C365         CATHARINA       Ilon      ILON           (null)     (null)          NameHyphen#Y   CorresLang#D  1970-06-14  0              Civil stat#L  1970-06-14        Protection#0  (null)      (null)      Sex#W  (null)          (null)               (null)   (null)     (null)       (null)          (null)             (null)        (null)         (null)           (null)              (null)         (null)          (null)      (null)            (null)        (null)         (null)            (null)            (null)           (null)             (null)      (null)    (null)       (null)            (null)         (null)          (null)           (null)        Country#SE    (null)            7564236036675  (null)       (null)          Country#CH        (null)                (null)        (null)            (null)         (null)     (null)       (null)      (null)    Decision#N    (null)          (null)      (null)       (null)   N     N      2008-01-01  9999-12-31  (null)    (null)         2008-10-23 05:54:21  
*/
select * from VISTA.TIKCOLLECTION where vnr = '7564236036675';
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE  CSZ       VNR            VNRNAME                      VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE  ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          
----------  ---------  ----------  ----------  ----------  --------  --------  -------------  ---------------------------  -------------  -----------  -----------  ------------  ----------------  ---------  -------------------  ---------  ------------------  --------  ---------------  -------------------  
1327306839  407376247  2014-05-28  1           0           DUF       SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2014-05-30    (null)            (null)     VDR4814580013500141  (null)     N                   N         (null)           2014-06-02 20:28:45  
5128982807  407376247  2020-02-06  1           0           ZH322     SZMZR#98  7564236036675  ILON,CATHARINA BENGTSDOTTER  (null)         (null)       (null)       2020-02-06    (null)            (null)     VDR3714210042764364  (null)     N                   N         5094016989       2020-02-14 07:54:48  
*/
SELECT * FROM vista.JIKZIKREQUEST WHERE KPVROLEID=385900367;
/*
TIKZIKREQID  KPVROLEID  CORRESPONCEADDRESSID  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CLOSINGDATE  CRESIDANCECODE  CCODELA  VNRLA   VNRLANAME  VISTADOCREF          DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                      OPERATION  
-----------  ---------  --------------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -----------  --------------  -------  ------  ---------  -------------------  ------------------  --------  ---------------  -------------------  -------------------  -----------  -------------------------------------------  ---------  
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 09:08:30  2020-01-27 09:08:30  ZH791        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  I          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 09:08:30  2020-01-27 16:01:41  ZHIK0A01     IK:IKJB10101D:5094810044                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-01-27        (null)          MZRFEHLER#-2     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-27 16:01:41  2020-01-28 20:27:31  ZHIK0A01     IK:IKJMEBB102:5102148698                     U          
5125905344   385900367  (null)                SZMZR#98  ZH322     2020-02-06   774838  (null)            (null)          MZRFEHLER#-1     (null)                ZH322      (null)       (null)          (null)   (null)  (null)     VDR3714210042764364  N                   N         (null)           2020-02-06 14:28:35  2020-02-06 14:28:35  ZH322        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  I          
5125905344   385900367  (null)                SZMZR#98  ZH322     2020-02-06   774838  (null)            (null)          MZRFEHLER#-1     (null)                ZH322      (null)       (null)          (null)   (null)  (null)     VDR3714210042764364  N                   N         (null)           2020-02-06 14:28:35  2020-02-06 16:01:05  ZHIK0A01     IK:IKJB10101D:5126047757                     U          
5125905344   385900367  (null)                SZMZR#98  ZH322     2020-02-06   774838  2020-02-06        (null)          MZRFEHLER#-2     (null)                ZH322      (null)       (null)          (null)   (null)  (null)     VDR3714210042764364  N                   N         (null)           2020-02-06 16:01:05  2020-02-07 20:26:00  ZHIK0A01     IK:IKJMEBB102:5128948081                     U          
5125905344   385900367  (null)                SZMZR#98  ZH322     2020-02-06   774838  2020-02-06        2020-02-06      MZRFEHLER#0      (null)                ZH322      (null)       (null)          (null)   (null)  (null)     VDR3714210042764364  N                   N         (null)           2020-02-07 20:26:00  2020-02-07 20:27:31  ZHIK0A01     IK:IKJB11101:5128978991                      D          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-01-27        2020-01-27      MZRFEHLER#4      (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-01-28 20:27:31  2020-02-19 14:43:49  ZH208        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 14:43:49  2020-02-19 16:01:06  ZHIK0A01     IK:IKJB10101D:5154350421                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-02-19        (null)          MZRFEHLER#-2     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 16:01:06  2020-02-19 22:10:10  ZHIK0A01     IK:IKJMEBB102:5154775392                     U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  2020-02-19        2020-02-19      MZRFEHLER#4      (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-02-19 22:10:10  2020-03-25 06:50:46  ZH208        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  U          
5094016990   385900367  (null)                SZMZR#97  ZH791     2020-01-27   760176  (null)            (null)          MZRFEHLER#-1     (null)                ZH791      (null)       (null)          (null)   (null)  (null)     VDR2709070042625669  N                   J         5094016989       2020-03-25 06:50:46  2020-03-25 16:00:40  ZHIK0A01     IK:IKJB10101D:5236017677                     U          
*/

-- Corona-Change
SELECT * FROM vista.TIKEMPLOYERARCHIVE WHERE billnbr='55555555555';


select * from vista.tsfmqinbound order by lastupdated desc;
select * from vista.tiscmcode where code_id like '%CorresLang#%'

update vista.tiscmcode set company_shortcode='PV', const_field='CORRESLANGUAGE_F', value='2', cdate=current timestamp where code_id like '%CorresLang#F';


SELECT TPVPARTID,KPVPARTID,BIRTHDATE,CCIVILSTATUS,CIVILSTATUSSINCE,CSEPARATION,VALIDFROM,VALIDTO FROM vista.tpvpartner WHERE kpvpartid=167913806;
SELECT TPVPARTID,KPVPARTID,BIRTHDATE,CCIVILSTATUS,CIVILSTATUSSINCE,CSEPARATION,VALIDFROM,VALIDTO FROM vista.tpvpartner WHERE kpvpartid=30005;
SELECT TPVPARTID,KPVPARTID,BIRTHDATE,CCIVILSTATUS,CIVILSTATUSSINCE,CSEPARATION,VALIDFROM,VALIDTO FROM vista.tpvpartner WHERE kpvpartid=7036895;

-- [EXTERNAL] WG: eduNE: PVJREPLI mit Error - BR_ABORT_CALC_WORKLOAD_ERROR
-- from PvPartnerDE pvPartnerDE where pvPartnerDE.pvPartnerKeyByKpvpartid=? and pvPartnerDE.cpartnertype = ? and  pvPartnerDE.validFrom <= ? and pvPartnerDE.validTo >= ?]and values [(6424, PartnerTyp#NP, 2020-04-21, 2020-04-21)].]
select * from vista.tpvpartner where kpvpartid=6424;
select distinct birthdateprec from vista.tpvpartner;

-- PV.2019.59882 (PV-Suche Verschiedene Resultate fÃ¼r NNP)
select * from vista.tpvpartner where kpvpartid=168018887;
update vista.tpvpartner set clegaltype='NNPersonTy#VERS', lastupdated=current timestamp where kpvpartid=168018887;

-- Java 8 Testing
-- Adresse gelÃ¶scht:
-- SQLCODE=-204, SQLSTATE=42704, SQLERRMC=VISTA.NTAIREPLICATION
select * from vista.aaireplication;


-- Analyze: Vista Java 8 (IK) BSV Statistik wird mit Error erstellt
select count(distinct coll1.tikcollectionid) from vista.tikcollection as coll1, vista.tikcollection as coll2,  
vista.tikzikorder as zikorder  
where year(coll1.entrancedate) = ?1  
and coll1.csz = ?2  
and zikorder.CSz in (?3, ?4, ?5, ?6, ?7, ?8, ?9)  
and year(zikorder.transmissiondate) <= ?10  
and ( zikorder.vnr.vnr = coll1.vnr or zikorder.vnr.vnr = coll1.vnrlaspouse )  
and coll1.vnr=coll2.vnrlaspouse and coll1.vnrlaspouse=coll2.vnr;

-- LZ.PV-I003: Neuer Service fÃ¼r Rollenbewirtschaftung durch IPV (PV.2020.76231)
-- Rollen mit Tagesdatum
select validfrom, count(*) as cnt_vb from vista.tpvrole
where croletype='Rolle#VB'
group by validfrom order by 2 desc;

-- 227527 - SZ - Vista liefert nur noch den Versicherten als OriginalempfÃ¤nger an ELAR zurÃ¼ck, was fachlich falsch ist.
/*
Weitere Adressen, vor allem die des Rechtsbeistands, werden nicht mehr zurÃ¼ckgegeben.
Das ist ein gleicher Fall wie im Ticket 227642.
------------------------
04.05.20 11:26:05.62: executeFunction: sequenceID=2443077, functionID=PV-WP-04, vistaDocRef=VDR3008110004953138, indexValues={{PID=365573132600970},{FACHCONTEXT=EK}}
04.05.20 11:26:06.25: executeFunction: return={{R_TOTADR=1},{R_01NAME=Schuler},{R_01SURNAME=Karl},{R_01ADDR1=Herr},{R_01ADDR2=Karl Schuler},{R_01ADDR3=Stiftung BSZ},{R_01ADDR4=Hausmatt 9},{R_01ADDR5=6423 Seewen SZ},{R_01ADDR6=},{R_01ADDR7=},{R_01ADDRESSTYPE=AA},{R_01ADDRESSEETYPE=},{R_01RELTYPE=},{R_01LEGALGUARDTYPE=},{R_01SEX=1},{R_01ADDRESSSWITCH=1},{R_01ORIGINALSWITCH=0},{R_01LANGUAGE=1},{R_01TITLELINE=Guten Tag Herr Schuler},{R_SUBJECT=Schuler Karl, RÃ¤bengasse 13, 6422 Steinen},{STATUS=VOLLSTAENDIG}} (sequenceID=2443077, functionID=PV-WP-04, vistaDocRef=VDR3008110004953138, indexValues={{PID=365573132600970},{FACHCONTEXT=EK}})
*/
select * from vista.tpvpartner where kpvpartid=365573132600970;
select * from vista.tpvelarpid where elarpid='365573132600970'; -- kpvpartid=1570001
select * from vista.tpvpartner where kpvpartid=1570001; -- 7563837866919
select * from vista.tpvrole where kpvpartid=1570001; -- EL = 38160325, STA = 1570025
select * from vista.tpvaddress where kpvpartid=1570001;
with CTE_ELDO as (
    select distinct ro.KPVPARTID
    from vista.TPVROLEREL rel
    join vista.TPVROLE ro on ro.KPVROLEID = rel.KPVROLEID_SOURCE
    where rel.CCORRADDRESSEETYPE = 'Correspond#ELDO'
)
select p.KPVPARTID, p.PERSONID, ro.KPVROLEID, p.NAME, p.FIRSTNAME, rel.KPVRRELID, rel.CRELATIONTYPE, rel.KPVROLEID_SOURCE, rel.KPVROLEID_TARGET, rel.KPVADRSID_CORR, rel.CCORRADDRESSEETYPE, rel.VALIDTO,
adr.CADDRESSTYPE, adrb.STREET, adr.STREETNR, adrb.ZIP, adrb.CITY
from CTE_ELDO eldo
join vista.TPVPARTNER p on eldo.kpvpartid = p.KPVPARTID
left outer join vista.TPVROLE ro on ro.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel on (rel.KPVROLEID_SOURCE = ro.KPVROLEID and rel.VALIDTO > current date)
left outer join vista.TPVADDRESS adr on (adr.KPVADRSID = rel.KPVADRSID_CORR and adr.VALIDTO > current date)
left outer join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.PERSONID = '7563837866919'
and p.VALIDTO > current date
--and rel.CCORRADDRESSEETYPE like '%EL%'
and rel.KPVADRSID_CORR is not null
fetch first 1000 rows only;
--> Jailer.

-- 227642 - SG - KorrDot (wie oben bei SZ)
select * from vista.tpvelarpid where elarpid='918704931802239'; -- kpvpartid=10097004
select * from vista.tpvpartner where kpvpartid=10097004;
select * from vista.tpvaddress where kpvpartid=10097004;
select * from vista.tpvpartner where kpvpartid in (
select kpvpartid from vista.TPVADDRESS where KPVADRSID in (13808087,14501318,14293384,1274371526,14501318));

-- 227783 - GR - Korr.dot (wie oben)
select * from vista.tpvelarpid where elarpid='096435512001251'; -- kpvpartid=1935758
select * from vista.tpvpartner where kpvpartid=1935758; -- Pascal Riedi
select * from vista.tpvaddress where kpvpartid=1935758 order by caddresstype, validto desc; -- WS + ZA
/*
04.05.20 17:23:39.89: executeFunction: sequenceID=2777525, functionID=PV-WP-04, vistaDocRef=VDR2517210007326795, indexValues={{PID=096435512001251},{FACHCONTEXT=EL}}
04.05.20 17:23:42.53: executeFunction: return={{R_TOTADR=2},{R_01NAME=AHV-Zweigstelle Thusis},{R_01SURNAME=},{R_01ADDR1=AHV-Zweigstelle Thusis},{R_01ADDR2=Rathaus},{R_01ADDR3=7430 Thusis},{R_01ADDR4=},{R_01ADDR5=},{R_01ADDR6=},{R_01ADDR7=},{R_01ADDRESSTYPE=GS},{R_01ADDRESSEETYPE=ELDK},{R_01RELTYPE=KE},{R_01LEGALGUARDTYPE=},{R_01SEX=3},{R_01ADDRESSSWITCH=0},{R_01ORIGINALSWITCH=0},{R_01LANGUAGE=1},{R_01TITLELINE=Guten Tag},{R_02NAME=Riedi},{R_02SURNAME=Pascal Andreas},{R_02ADDR1=Herr},{R_02ADDR2=Pascal Andreas Riedi},{R_02ADDR3=Mansio SchilfluggÃ¤},{R_02ADDR4=Seeblickstrasse 3},{R_02ADDR5=8596 MÃ¼nsterlingen},{R_02ADDR6=},{R_02ADDR7=},{R_02ADDRESSTYPE=ZA},{R_02ADDRESSEETYPE=},{R_02RELTYPE=},{R_02LEGALGUARDTYPE=},{R_02SEX=1},{R_02ADDRESSSWITCH=1},{R_02ORIGINALSWITCH=0},{R_02LANGUAGE=1},{R_02TITLELINE=Guten Tag Herr Riedi},{R_SUBJECT=Riedi Pascal Andreas, Schulweg 7A, 7430 Thusis},{STATUS=VOLLSTAENDIG}} (sequenceID=2777525, functionID=PV-WP-04, vistaDocRef=VDR2517210007326795, indexValues={{PID=096435512001251},{FACHCONTEXT=EL}})
*/
-- PROD: 2 Addresses: ELDK, ZA --> ELDO? ELOE?
-- AIT: 3 Addresses: ELOE, ELDK, ZA --> ELDO?

-- not exported partner:
select * from vista.tpvpartner where kpvpartid=11144236;
INSERT INTO VISTA.TPVPARTNER (TPVPARTID, KPVPARTID, KPVPARTID_COURT, KPVPARTID_REDUNDANZ, KPVPARTID_MUNAUTOR, KPVPARTID_HEIRREPRESENT, KPVPARTID_BEQUEATHER, KPVPARTID_TAXDOMICILE, KPVPARTID_AHVBRANCHNR, KPVPARTID_OFFICEOPERATIONNR, KPVPARTID_BANKRUPTCY, CPARTNERTYPE, SOCIALSECNR, TITEL, NAME, NAMESX, UPPERNAME, FIRSTNAME, FIRSTNAMESX, UPPERFIRSTNAME, LASTNAME, UPPERLASTNAME, BIRTHNAME, UPPERBIRTHNAME, CNAMESEQUENCE, CLANGUAGE, BIRTHDATE, BIRTHDATEPREC, CCIVILSTATUS, CIVILSTATUSSINCE, CCONFIDLEVEL, CLEGALTYPE, CLEGALFORM, CSEX, ADDITIONALNAME, UPPERADDITIONALNAME, CCANTON, COMPANYNR, AHVBRANCHNR, CAHVCHIEFSALUT, AHVCHIEFFIRSTNAME, AHVCHIEFNAME, AHVCHIEFSINCE, CAHVDEPUTYSALUT, AHVDEPUTYFIRSTNAME, AHVDEPUTYNAME, AHVDEPUTYSINCE, COMPFUNDNR, COMPFUNDBRANCHNR, COMPFUNDCEDE, CCOMPFUNDTYPE, CCOMPFUNDFAKTYPE, COMPFUNDFUSIONNR, COMPFUNDFUBRANR, OFFICEOPERATIONNR, IVOFFICENR, KKABSVNR, MUNAUTHORNR, CMUNAUTHORCANTON, CMUNAUTHORFLG, CINSURANCETYPE, INSURANCESUVANR, AGENCYNUMBER, CCITIZENSHIP, CITIZENSHIPSINCE, PERSONID, CSEPARATION, SEPARATIONDATE, CCOUNTRYOFLIVING, COUNTRYOFLIVINGSINCE, CRESIDAUTHOR, RESIDAUTHORSINCE, RESIDAUTHORTO, DEATHDATE, CTAXCOUNTRY, CTAXCANTON, TAXREGNR, CTAXATSOURCE, BFSMUNITIPALNR, CCOURTTYPE, CCLERKALLOC, REMARKS, ISVIC, VALIDFROM, VALIDTO, TEMP9999, EXTPARTNERKEY, LASTUPDATED) VALUES (11144234, 11144236, null, null, null, null, null, null, null, null, null, 'PartnerTyp#NNP', null, null, 'Amtsvormundschaft', 'A532', 'AMTSVORMUNDSCHAFT', null, null, null, null, null, null, null, null, 'CorresLang#D', null, null, null, null, 'Protection#0', 'NNPersonTy#NNP', 'LegalFormC#OEF', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 'N', 'N', '1900-01-01', '2012-12-31', null, null, '2012-11-16 07:11:34');
INSERT INTO VISTA.TPVPARTNER (TPVPARTID, KPVPARTID, KPVPARTID_COURT, KPVPARTID_REDUNDANZ, KPVPARTID_MUNAUTOR, KPVPARTID_HEIRREPRESENT, KPVPARTID_BEQUEATHER, KPVPARTID_TAXDOMICILE, KPVPARTID_AHVBRANCHNR, KPVPARTID_OFFICEOPERATIONNR, KPVPARTID_BANKRUPTCY, CPARTNERTYPE, SOCIALSECNR, TITEL, NAME, NAMESX, UPPERNAME, FIRSTNAME, FIRSTNAMESX, UPPERFIRSTNAME, LASTNAME, UPPERLASTNAME, BIRTHNAME, UPPERBIRTHNAME, CNAMESEQUENCE, CLANGUAGE, BIRTHDATE, BIRTHDATEPREC, CCIVILSTATUS, CIVILSTATUSSINCE, CCONFIDLEVEL, CLEGALTYPE, CLEGALFORM, CSEX, ADDITIONALNAME, UPPERADDITIONALNAME, CCANTON, COMPANYNR, AHVBRANCHNR, CAHVCHIEFSALUT, AHVCHIEFFIRSTNAME, AHVCHIEFNAME, AHVCHIEFSINCE, CAHVDEPUTYSALUT, AHVDEPUTYFIRSTNAME, AHVDEPUTYNAME, AHVDEPUTYSINCE, COMPFUNDNR, COMPFUNDBRANCHNR, COMPFUNDCEDE, CCOMPFUNDTYPE, CCOMPFUNDFAKTYPE, COMPFUNDFUSIONNR, COMPFUNDFUBRANR, OFFICEOPERATIONNR, IVOFFICENR, KKABSVNR, MUNAUTHORNR, CMUNAUTHORCANTON, CMUNAUTHORFLG, CINSURANCETYPE, INSURANCESUVANR, AGENCYNUMBER, CCITIZENSHIP, CITIZENSHIPSINCE, PERSONID, CSEPARATION, SEPARATIONDATE, CCOUNTRYOFLIVING, COUNTRYOFLIVINGSINCE, CRESIDAUTHOR, RESIDAUTHORSINCE, RESIDAUTHORTO, DEATHDATE, CTAXCOUNTRY, CTAXCANTON, TAXREGNR, CTAXATSOURCE, BFSMUNITIPALNR, CCOURTTYPE, CCLERKALLOC, REMARKS, ISVIC, VALIDFROM, VALIDTO, TEMP9999, EXTPARTNERKEY, LASTUPDATED) VALUES (449133023, 11144236, null, null, null, null, null, null, null, null, null, 'PartnerTyp#NNP', null, null, 'Soziale Dienste St. Gallen', 'S243', 'SOZIALE DIENSTE ST. GALLEN', null, null, null, null, null, null, null, null, 'CorresLang#D', null, null, null, null, 'Protection#0', 'NNPersonTy#NNP', 'LegalFormC#OEF', null, 'Berufsbeistandschaft', 'BERUFSBEISTANDSCHAFT', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 'N', 'N', '2013-01-01', '9999-12-31', null, null, '2019-12-19 16:29:16');


-- 227783 - GR - Korr.dot (wie oben) - FÃ¤lle von AndrÃ© aus SZ und SG
-- Fall 1 (SZ)
with CTE_ELDO as (
    select distinct ro.KPVPARTID
    from vista.TPVROLEREL rel
    join vista.TPVROLE ro on ro.KPVROLEID = rel.KPVROLEID_SOURCE
    where rel.CCORRADDRESSEETYPE = 'Correspond#ELDO'
)
select p.KPVPARTID, p.PERSONID, ro.KPVROLEID, p.NAME, p.FIRSTNAME, rel.KPVRRELID, rel.CRELATIONTYPE, rel.KPVROLEID_SOURCE, rel.KPVROLEID_TARGET, rel.KPVADRSID_CORR, rel.CCORRADDRESSEETYPE, rel.VALIDTO,
adr.CADDRESSTYPE, adrb.STREET, adr.STREETNR, adrb.ZIP, adrb.CITY
from CTE_ELDO eldo
join vista.TPVPARTNER p on eldo.kpvpartid = p.KPVPARTID
left outer join vista.TPVROLE ro on ro.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel on (rel.KPVROLEID_SOURCE = ro.KPVROLEID and rel.VALIDTO > current date)
left outer join vista.TPVADDRESS adr on (adr.KPVADRSID = rel.KPVADRSID_CORR and adr.VALIDTO > current date)
left outer join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.PERSONID = '7563837866919'
and p.VALIDTO > current date
--and rel.CCORRADDRESSEETYPE like '%EL%'
and rel.KPVADRSID_CORR is not null
fetch first 1000 rows only;
/*
KPVPARTID  PERSONID       KPVROLEID  NAME     FIRSTNAME  KPVRRELID  CRELATIONTYPE  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVADRSID_CORR  CCORRADDRESSEETYPE  VALIDTO     CADDRESSTYPE   STREET       STREETNR  ZIP     CITY       
---------  -------------  ---------  -------  ---------  ---------  -------------  ----------------  ----------------  --------------  ------------------  ----------  -------------  -----------  --------  ------  ---------  
1570001    7563837866919  1570025    Schuler  Karl       156274335  RoleRelati#GV  1570025           109821629         109684792       (null)              9999-12-31  AddressTyp#GS  Parkstrasse  16        641000  Goldau     
1570001    7563837866919  37432472   Schuler  Karl       37432495   RoleRelati#KE  37432472          1570025           3993429         Correspond#REK      9999-12-31  AddressTyp#AA  Hausmatt     9         642300  Seewen SZ  
1570001    7563837866919  37432472   Schuler  Karl       156274366  RoleRelati#KE  37432472          109684721         109684792       Correspond#REK      9999-12-31  AddressTyp#GS  Parkstrasse  16        641000  Goldau     
1570001    7563837866919  38160325   Schuler  Karl       83176569   RoleRelati#KE  38160325          1570025           3909198         Correspond#ELOE     9999-12-31  AddressTyp#WS  RÃ¤bengasse   13        642200  Steinen    
1570001    7563837866919  38160325   Schuler  Karl       38225307   RoleRelati#KE  38160325          109684721         109684792       Correspond#ELDO     9999-12-31  AddressTyp#GS  Parkstrasse  16        641000  Goldau     
1570001    7563837866919  38160325   Schuler  Karl       526986073  RoleRelati#KE  38160325          1570025           3909198         Correspond#ELDR     9999-12-31  AddressTyp#WS  RÃ¤bengasse   13        642200  Steinen    
1570001    7563837866919  146266703  Schuler  Karl       146266743  RoleRelati#KE  146266703         1570025           3909198         Correspond#VBV      9999-12-31  AddressTyp#WS  RÃ¤bengasse   13        642200  Steinen    
1570001    7563837866919  146266703  Schuler  Karl       149345672  RoleRelati#KE  146266703         109684721         109684792       Correspond#VBV      9999-12-31  AddressTyp#GS  Parkstrasse  16        641000  Goldau     
1570001    7563837866919  146266703  Schuler  Karl       149345674  RoleRelati#KE  146266703         109684721         109684792       Correspond#VBA      9999-12-31  AddressTyp#GS  Parkstrasse  16        641000  Goldau     
*/
-- Fall2 (SG)
with CTE_ELDO as (
    select distinct ro.KPVPARTID
    from vista.TPVROLEREL rel
    join vista.TPVROLE ro on ro.KPVROLEID = rel.KPVROLEID_SOURCE
    where rel.CCORRADDRESSEETYPE = 'Correspond#ELDO'
)
select p.KPVPARTID, p.PERSONID, ro.KPVROLEID, p.NAME, p.FIRSTNAME, rel.KPVRRELID, rel.CRELATIONTYPE, rel.KPVROLEID_SOURCE, rel.KPVROLEID_TARGET, rel.KPVADRSID_CORR, rel.CCORRADDRESSEETYPE, rel.VALIDTO,
adr.CADDRESSTYPE, adrb.STREET, adr.STREETNR, adrb.ZIP, adrb.CITY
from CTE_ELDO eldo
join vista.TPVPARTNER p on eldo.kpvpartid = p.KPVPARTID
left outer join vista.TPVROLE ro on ro.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel on (rel.KPVROLEID_SOURCE = ro.KPVROLEID and rel.VALIDTO > current date)
left outer join vista.TPVADDRESS adr on (adr.KPVADRSID = rel.KPVADRSID_CORR and adr.VALIDTO > current date)
left outer join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.PERSONID = '7562965951016'
and p.VALIDTO > current date
--and rel.CCORRADDRESSEETYPE like '%EL%'
and rel.KPVADRSID_CORR is not null
fetch first 1000 rows only;
/*
KPVPARTID  PERSONID       KPVROLEID  NAME   FIRSTNAME  KPVRRELID   CRELATIONTYPE  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVADRSID_CORR  CCORRADDRESSEETYPE  VALIDTO     CADDRESSTYPE   STREET              STREETNR  ZIP     CITY        
---------  -------------  ---------  -----  ---------  ----------  -------------  ----------------  ----------------  --------------  ------------------  ----------  -------------  ------------------  --------  ------  ----------  
8733465    7562965951016  8733471    BÃ¶sch  Ernst      2414850723  RoleRelati#GV  8733471           2414850720        2310101593      (null)              9999-12-31  AddressTyp#WS  Buechschachen       2234      910000  Herisau     
8733465    7562965951016  63648275   BÃ¶sch  Ernst      63648331    RoleRelati#KE  63648275          6977549           13454214        Correspond#REK      9999-12-31  AddressTyp#WS  SonnenhÃ¼gelstrasse  1         912600  Necker      
8733465    7562965951016  63648275   BÃ¶sch  Ernst      63648688    RoleRelati#KE  63648275          8733471           51699146        Correspond#REK      9999-12-31  AddressTyp#ZA  Feldeggstrasse      8         911300  Degersheim  
8733465    7562965951016  65032302   BÃ¶sch  Ernst      195500466   RoleRelati#KE  65032302          8733471           12288945        Correspond#ELOE     9999-12-31  AddressTyp#WS  SonnenhÃ¼gelstrasse  1         912600  Necker      
8733465    7562965951016  65032302   BÃ¶sch  Ernst      195500468   RoleRelati#KE  65032302          8733471           12288945        Correspond#ELOE     9999-12-31  AddressTyp#WS  SonnenhÃ¼gelstrasse  1         912600  Necker      
8733465    7562965951016  65032302   BÃ¶sch  Ernst      231751948   RoleRelati#KE  65032302          8733471           12288945        Correspond#ELOE     9999-12-31  AddressTyp#WS  SonnenhÃ¼gelstrasse  1         912600  Necker      
8733465    7562965951016  65032302   BÃ¶sch  Ernst      1853805870  RoleRelati#KE  65032302          8733471           12288945        Correspond#ELDR     9999-12-31  AddressTyp#WS  SonnenhÃ¼gelstrasse  1         912600  Necker      
8733465    7562965951016  65032302   BÃ¶sch  Ernst      66118892    RoleRelati#KE  65032302          2310101474        2310101593      Correspond#ELDO     9999-12-31  AddressTyp#WS  Buechschachen       2234      910000  Herisau     
(...)
*/
-- Fall 3 (SG)
with CTE_ELDO as (
    select distinct ro.KPVPARTID
    from vista.TPVROLEREL rel
    join vista.TPVROLE ro on ro.KPVROLEID = rel.KPVROLEID_SOURCE
    where rel.CCORRADDRESSEETYPE = 'Correspond#ELDO'
)
select p.KPVPARTID, p.PERSONID, ro.KPVROLEID, p.NAME, p.FIRSTNAME, rel.KPVRRELID, rel.CRELATIONTYPE, rel.KPVROLEID_SOURCE, rel.KPVROLEID_TARGET, rel.KPVADRSID_CORR, rel.CCORRADDRESSEETYPE, rel.VALIDTO,
adr.CADDRESSTYPE, adrb.STREET, adr.STREETNR, adrb.ZIP, adrb.CITY
from CTE_ELDO eldo
join vista.TPVPARTNER p on eldo.kpvpartid = p.KPVPARTID
left outer join vista.TPVROLE ro on ro.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel on (rel.KPVROLEID_SOURCE = ro.KPVROLEID and rel.VALIDTO > current date)
left outer join vista.TPVADDRESS adr on (adr.KPVADRSID = rel.KPVADRSID_CORR and adr.VALIDTO > current date)
left outer join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.PERSONID = '7566541200611'
and p.VALIDTO > current date
--and rel.CCORRADDRESSEETYPE like '%EL%'
and rel.KPVADRSID_CORR is not null
fetch first 1000 rows only;

-- Fall aus GR (AIT 101)
-- Fall 3 (SG)
with CTE_ELDO as (
    select distinct ro.KPVPARTID
    from vista.TPVROLEREL rel
    join vista.TPVROLE ro on ro.KPVROLEID = rel.KPVROLEID_SOURCE
    where rel.CCORRADDRESSEETYPE = 'Correspond#ELDO'
)
select p.KPVPARTID, p.PERSONID, ro.KPVROLEID, p.NAME, p.FIRSTNAME, rel.KPVRRELID, rel.CRELATIONTYPE, rel.KPVROLEID_SOURCE, rel.KPVROLEID_TARGET, rel.KPVADRSID_CORR, rel.CCORRADDRESSEETYPE, rel.VALIDTO,
adr.CADDRESSTYPE, adrb.STREET, adr.STREETNR, adrb.ZIP, adrb.CITY
from CTE_ELDO eldo
join vista.TPVPARTNER p on eldo.kpvpartid = p.KPVPARTID
left outer join vista.TPVROLE ro on ro.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel on (rel.KPVROLEID_SOURCE = ro.KPVROLEID and rel.VALIDTO > current date)
left outer join vista.TPVADDRESS adr on (adr.KPVADRSID = rel.KPVADRSID_CORR and adr.VALIDTO > current date)
left outer join vista.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.PERSONID = '7567150345489'
and p.VALIDTO > current date
--and rel.CCORRADDRESSEETYPE like '%EL%'
and rel.KPVADRSID_CORR is not null
fetch first 1000 rows only;
/*
KPVPARTID  PERSONID       KPVROLEID  NAME   FIRSTNAME       KPVRRELID  CRELATIONTYPE  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVADRSID_CORR  CCORRADDRESSEETYPE  VALIDTO     CADDRESSTYPE   STREET             STREETNR  ZIP     CITY       
---------  -------------  ---------  -----  --------------  ---------  -------------  ----------------  ----------------  --------------  ------------------  ----------  -------------  -----------------  --------  ------  ---------  
1935758    7567150345489  387502776  Riedi  Pascal Andreas  387502917  RoleRelati#KE  387502776         4424101           5076468         Correspond#REK      9999-12-31  AddressTyp#GS  Steinbruchstrasse  18        700000  Chur       
1935758    7567150345489  387502776  Riedi  Pascal Andreas  395926286  RoleRelati#KE  387502776         4290645           5935519         Correspond#REK      9999-12-31  AddressTyp#GS  Ottostrasse        24        700000  Chur       
1935758    7567150345489  387502776  Riedi  Pascal Andreas  395928469  RoleRelati#KE  387502776         4465567           6517939         Correspond#REK      9999-12-31  AddressTyp#GS  Ottostrasse        24        700000  Chur       
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413113  RoleRelati#RV  397411718         36973711          34856520        (null)              9999-12-31  AddressTyp#GS  Rathausplatz       1         720600  Igis       
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413363  RoleRelati#KE  397411718         4585498           5560308         Correspond#VBV      9999-12-31  AddressTyp#GS  StÃ¤dtli            10        730400  Maienfeld  
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413365  RoleRelati#KE  397411718         4585498           5560308         Correspond#VBA      9999-12-31  AddressTyp#GS  StÃ¤dtli            10        730400  Maienfeld  
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413394  RoleRelati#KE  397411718         33563341          34856520        Correspond#VBV      9999-12-31  AddressTyp#GS  Rathausplatz       1         720600  Igis       
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413396  RoleRelati#KE  397411718         33563341          34856520        Correspond#VBA      9999-12-31  AddressTyp#GS  Rathausplatz       1         720600  Igis       
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397413569  RoleRelati#KE  397411718         33563341          34856520        Correspond#VBK      9999-12-31  AddressTyp#GS  Rathausplatz       1         720600  Igis       
1935758    7567150345489  397411718  Riedi  Pascal Andreas  397414262  RoleRelati#KE  397411718         1935775           5027937         Correspond#VBK      9999-12-31  AddressTyp#WS  Schulweg           7A        743000  Thusis     
1935758    7567150345489  409731425  Riedi  Pascal Andreas  409749578  RoleRelati#KE  409731425         1935775           5027937         Correspond#ELOE     9999-12-31  AddressTyp#WS  Schulweg           7A        743000  Thusis     
1935758    7567150345489  409731425  Riedi  Pascal Andreas  438324161  RoleRelati#KE  409731425         30595363          30595375        Correspond#ELDK     9999-12-31  AddressTyp#GS  Rathaus            (null)    743000  Thusis     
1935758    7567150345489  1935775    Riedi  Pascal Andreas  516370021  RoleRelati#GV  1935775           8249808           5398651         (null)              9999-12-31  AddressTyp#GS  Untere Gasse       1         743000  Thusis     
1935758    7567150345489  387502776  Riedi  Pascal Andreas  516370555  RoleRelati#KE  387502776         4304360           5398651         Correspond#REK      9999-12-31  AddressTyp#GS  Untere Gasse       1         743000  Thusis     
1935758    7567150345489  409731425  Riedi  Pascal Andreas  409750498  RoleRelati#KE  409731425         4304360           5398651         Correspond#ELDO     9999-12-31  AddressTyp#GS  Untere Gasse       1         743000  Thusis     
1935758    7567150345489  387502776  Riedi  Pascal Andreas  545307623  RoleRelati#KE  387502776         1935775           5027937         Correspond#REK      9999-12-31  AddressTyp#WS  Schulweg           7A        743000  Thusis     
1935758    7567150345489  397411718  Riedi  Pascal Andreas  560707631  RoleRelati#KE  397411718         4304360           5398651         Correspond#VBV      9999-12-31  AddressTyp#GS  Untere Gasse       1         743000  Thusis     
1935758    7567150345489  397411718  Riedi  Pascal Andreas  560707633  RoleRelati#KE  397411718         4304360           5398651         Correspond#VBA      9999-12-31  AddressTyp#GS  Untere Gasse       1         743000  Thusis     
1935758    7567150345489  409731425  Riedi  Pascal Andreas  719828659  RoleRelati#KE  409731425         1935775           5027937         Correspond#ELDR     9999-12-31  AddressTyp#WS  Schulweg           7A        743000  Thusis     
*/

select * from vista.tpvpartner where personid='7567150345489'; -- 1935758
select * from vista.tpvelarpid where kpvpartid=1935758; -- 096435512001251
-- Test - change GV-RoleRel-Address:
-- 1) update to GV-Address to 6517939 (REK)
update vista.tpvrolerel set kpvadrsid_corr=6517939, lastupdated=current timestamp where kpvrrelid=516370021 and crelationtype='RoleRelati#GV';


-- KEP Analysen
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NP';

-- 228226 - ZG - IK-Kurzregister: Fehlende KPVRegisterAddress
-- E52473
select * from vista.tikemployerarchive where billnbr='E52473';
-- kpvpartid = 381402738
select * from vista.tpvaddress where kpvpartid=381402738;


-- 228209 - ZH - PV-Repli: POLG auf NNP
select tpvpartid, kpvpartid, cpartnertype, name, clegaltype, additionalname, compfundnr, compfundbranchnr, compfundcede, cmunauthorcanton, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid=25512477;
/*
TPVPARTID  KPVPARTID  CPARTNERTYPE    NAME                           CLEGALTYPE      ADDITIONALNAME      COMPFUNDNR  COMPFUNDBRANCHNR  COMPFUNDCEDE  CMUNAUTHORCANTON  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  --------------  -----------------------------  --------------  ------------------  ----------  ----------------  ------------  ----------------  ----------  ----------  -------------------  
25512475   25512477   PartnerTyp#NNP  Personalamt des Kanton ZÃ¼rich  NNPersonTy#AK   Lohnadministration  999         995               N             CompoundFu#K      1900-01-01  2010-12-31  2010-12-20 11:04:35  
159621956  25512477   PartnerTyp#NNP  Kanton ZÃ¼rich                  NNPersonTy#AK   Finanzverwaltung    999         995               N             CompoundFu#K      2011-01-01  2011-12-31  2012-04-02 11:24:22  
739590298  25512477   PartnerTyp#NNP  Finanzdirektion Kanton ZÃ¼rich  NNPersonTy#NNP  (null)              (null)      (null)            (null)        (null)            2012-01-01  9999-12-31  2020-03-16 09:59:48  
*/
select tpvpartid, kpvpartid, cpartnertype, name, clegaltype, additionalname, compfundnr, compfundbranchnr, compfundcede, cmunauthorcanton, validfrom, validto, lastupdated, program 
from vista.jpvpartner where kpvpartid=25512477;


-- 77663 - SIT413 - SEDEX - unvollstÃ¤ndige Sammlung prozessiert
select * from vista.tikheader where vnr='7565871824931';
/*
TIKHEADID   TIKOWNRID   VNR            NAME                   BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  ---------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
1400682588  1400682587  7565871824931  KELLER,ANDREA MARTINA  1998       12          10        SEXCODEZAS#2  BSVLAND#100  7565871824931  T                2020-05-07 10:02:11  
*/
select * from vista.tikowner where tikownrid=1400682587; -- IK-Role: 1400682583
select * from vista.TZAXMLSDXRECORD where date(lastupdated) = '2020-05-07';

select * from vista.TZASEDEXATTACHMENT where date(lastupdated) = '2020-05-07';
select * from vista.tikkoaurequest where date(lastupdated) = '2020-05-07' and senderid='SEDEX';
/*
REQUESTID   MESSAGEID                      SENDERID  ISCOMPLETE  ZIKREQUESTID  TIKZIORID   ERRORCODE  ERRORMESSAGE  MESSAGEXML  LASTUPDATED          
----------  -----------------------------  --------  ----------  ------------  ----------  ---------  ------------  ----------  -------------------  
2405507995  S-311-0000001-20200506-153113  SEDEX     1           2405507993    2405509500  0          (null)        2405506375  2020-05-07 15:28:13  
2405508000  S-311-0000002-20200506-153113  SEDEX     1           2405507998    2405509528  0          (null)        2405506376  2020-05-07 15:28:21  
*/
/*
INSERT INTO VISTA.TIKKOAUREQUEST (REQUESTID, MESSAGEID, SENDERID, ISCOMPLETE, ZIKREQUESTID, TIKZIORID, ERRORCODE, ERRORMESSAGE, LASTUPDATED) VALUES (2405507995, 'S-311-0000001-20200506-153113', 'SEDEX', '1', 2405507993, 2405509500, '0', null, '2020-05-07 15:28:13');
INSERT INTO VISTA.TIKKOAUREQUEST (REQUESTID, MESSAGEID, SENDERID, ISCOMPLETE, ZIKREQUESTID, TIKZIORID, ERRORCODE, ERRORMESSAGE, LASTUPDATED) VALUES (2405508000, 'S-311-0000002-20200506-153113', 'SEDEX', '1', 2405507998, 2405509528, '0', null, '2020-05-07 15:28:21');
*/

select * from vista.jikzikrequest where tikzikreqid in (2405507993, 2405507998) order by tikzikreqid, change_date;
select * from vista.tikcustomer;
/*
TIKZIKREQID  KPVROLEID   CORRESPONCEADDRESSID  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CLOSINGDATE  CRESIDANCECODE  CCODELA  VNRLA   VNRLANAME  VISTADOCREF  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                   OPERATION  
-----------  ----------  --------------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -----------  --------------  -------  ------  ---------  -----------  ------------------  --------  ---------------  -------------------  -------------------  -----------  ------------------------  ---------  
2405507993   1400682583  (null)                SZMZR#98  SEDEX     2020-05-07   786624  (null)            (null)          MZRFEHLER#-1     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 09:44:03  2020-05-07 09:44:03  SGIK0A01     IK:IKJB11107:2405507931   I          
2405507993   1400682583  (null)                SZMZR#98  SEDEX     2020-05-07   786624  (null)            (null)          MZRFEHLER#-1     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 09:44:03  2020-05-07 10:01:47  SGIK0A01     IK:IKJB10101:2405509011   U          
2405507993   1400682583  (null)                SZMZR#98  SEDEX     2020-05-07   786624  2020-05-07        (null)          MZRFEHLER#-2     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 10:01:47  2020-05-07 10:02:11  SGIK0A01     IK:IKJMEBB102:2405509199  U          
2405507993   1400682583  (null)                SZMZR#98  SEDEX     2020-05-07   786624  2020-05-07        2020-05-06      MZRFEHLER#0      (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 10:02:11  2020-05-07 10:02:54  SGIK0A01     IK:IKJB11101:2405509380   D          
2405507998   1421158580  (null)                SZMZR#98  SEDEX     2020-05-07   786625  (null)            (null)          MZRFEHLER#-1     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 09:44:03  2020-05-07 09:44:03  SGIK0A01     IK:IKJB11107:2405507931   I          
2405507998   1421158580  (null)                SZMZR#98  SEDEX     2020-05-07   786625  (null)            (null)          MZRFEHLER#-1     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 09:44:03  2020-05-07 10:01:47  SGIK0A01     IK:IKJB10101:2405509011   U          
2405507998   1421158580  (null)                SZMZR#98  SEDEX     2020-05-07   786625  2020-05-07        (null)          MZRFEHLER#-2     (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 10:01:47  2020-05-07 10:02:12  SGIK0A01     IK:IKJMEBB102:2405509199  U          
2405507998   1421158580  (null)                SZMZR#98  SEDEX     2020-05-07   786625  2020-05-07        2020-05-06      MZRFEHLER#0      (null)                SGIK0A01   (null)       (null)          (null)   (null)  (null)     (null)       N                   N         (null)           2020-05-07 10:02:12  2020-05-07 10:02:55  SGIK0A01     IK:IKJB11101:2405509380   D          
*/
/*
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507993, 1400682583, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786624, null, null, 'MZRFEHLER#-1', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 09:44:03', '2020-05-07 09:44:03', 'SGIK0A01', 'IK:IKJB11107:2405507931', 'I');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507993, 1400682583, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786624, null, null, 'MZRFEHLER#-1', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 09:44:03', '2020-05-07 10:01:47', 'SGIK0A01', 'IK:IKJB10101:2405509011', 'U');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507993, 1400682583, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786624, '2020-05-07', null, 'MZRFEHLER#-2', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 10:01:47', '2020-05-07 10:02:11', 'SGIK0A01', 'IK:IKJMEBB102:2405509199', 'U');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507993, 1400682583, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786624, '2020-05-07', '2020-05-06', 'MZRFEHLER#0', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 10:02:11', '2020-05-07 10:02:54', 'SGIK0A01', 'IK:IKJB11101:2405509380', 'D');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507998, 1421158580, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786625, null, null, 'MZRFEHLER#-1', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 09:44:03', '2020-05-07 09:44:03', 'SGIK0A01', 'IK:IKJB11107:2405507931', 'I');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507998, 1421158580, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786625, null, null, 'MZRFEHLER#-1', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 09:44:03', '2020-05-07 10:01:47', 'SGIK0A01', 'IK:IKJB10101:2405509011', 'U');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507998, 1421158580, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786625, '2020-05-07', null, 'MZRFEHLER#-2', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 10:01:47', '2020-05-07 10:02:12', 'SGIK0A01', 'IK:IKJMEBB102:2405509199', 'U');
INSERT INTO VISTA.JIKZIKREQUEST (TIKZIKREQID, KPVROLEID, CORRESPONCEADDRESSID, CSZ, AKNOTICE, REQUESTDATE, MZRNBR, TRANSMISSIONDATE, ACCEPTANCEDATE, CPROCESSINGCODE, BPOBASKETENTRYCLOSED, CREATEDBY, CLOSINGDATE, CRESIDANCECODE, CCODELA, VNRLA, VNRLANAME, VISTADOCREF, DELIVERYTHIRDPARTY, AUTOSEND, TIKDELADDRESSID, LASTUPDATED, CHANGE_DATE, CHANGE_USER, PROGRAM, OPERATION) VALUES (2405507998, 1421158580, null, 'SZMZR#98', 'SEDEX', '2020-05-07', 786625, '2020-05-07', '2020-05-06', 'MZRFEHLER#0', null, 'SGIK0A01', null, null, null, null, null, null, 'N', 'N', null, '2020-05-07 10:02:12', '2020-05-07 10:02:55', 'SGIK0A01', 'IK:IKJB11101:2405509380', 'D');
*/
select * from vista.jikzikrequest where tikzikreqid=2405507993;

select * from vista.jikzikorder where tikziorid in (2405509500, 2405509528) order by tikziorid, change_date;
select * from vista.tikcollection where tikcollid in (2405509500, 2405509528);
select * from vista.jikcollection where tikcollid in (2405509500, 2405509528) order by tikcollid;
-- 2. Partner / 2. Sammlung:
select * from vista.tikheader where tikheadid=1421158584; -- 7561538157930, tikownrid = 1421158583
select * from vista.tikowner where tikownrid=1421158583; -- kpvroleid=1421158580
-- TIKBOOKING: TIKINRETID = 1442803550
select * from vista.tikbooking where tikinretid=1442803550;
select * from vista.tikstatistics where tikstatid=1442803550; -- empty
select * from vista.tikzasincomereport where tikinretid=1442803550; -- empty -- 1430593468
select * from vista.TIKZASPROCESSINGLOG; -- empty


-- 228510 / 228697 - GR - B&Z Core - LDAP Benutzerdaten werden nicht mit L&Z PV synchronisiert
/*
java.lang.IllegalArgumentException
	at com.ibm.vista.mq.pv.BZPVI003.V5.LanguageType.fromValue(LanguageType.java:51)
	at com.ibm.vista.pv.mq.BZPVI003.V5.PvReplicationMsgBean.copypvPartnerAEtailsToPartnerList(PvReplicationMsgBean.java:1354)
	*/
select * from vista.tpvrole where kpvroleid=929844238; -- MIT - kpvpartid = 929837919
select * from vista.tpvpartner where kpvpartid=929837919; -- clanguage = CorresLang#D (OK)
select * from vista.jpvpartner where kpvpartid=929837919;
-- 414d51205453533147525020202020209dff775e26f54517
select * from vista.tsfmqoutbound where jmsmessageid='ID:414d51205453533147525020202020209dff775e26f54517'; -- empty
select * from vista.tsfmqoutbound where jmscorrelationid='f1d0da3d-2431-4a32-b576-e104fd885f55';
/*
TSFMQOUTBOUNDID  STATUS  REASON               EXECTIMEMDB  EXECTIMESRV  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID  JMSTIMESTAMP  JMSCORRELATIONID                      JMSDESTINATION  JMSREPLYTO  JMSREDELIVERED  JMSXAPPID  JMSXDELIVERYCOUNT  JMSXUSERID  JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID  TENANTID  TOPIC   USERNAME  USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  OUTBOUNDMSG  LASTUPDATED          
---------------  ------  -------------------  -----------  -----------  ---------------  ----------  ---------------  -------------  -----------  ------------  ------------  ------------------------------------  --------------  ----------  --------------  ---------  -----------------  ----------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  -----------------  --------  ------  --------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  -----------  -------------------  
937822121        0       MQOUTBREJ#BEANERROR  125          78           (null)           BZ.PV-I003  (null)           (null)         (null)       (null)        (null)        f1d0da3d-2431-4a32-b576-e104fd885f55  (null)          (null)      (null)          (null)     (null)             (null)      (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)             (null)    (null)  (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)       2020-05-15 10:09:26  
937822145        0       MQOUTBREJ#BEANERROR  94           62           (null)           BZ.PV-I003  (null)           (null)         (null)       (null)        (null)        f1d0da3d-2431-4a32-b576-e104fd885f55  (null)          (null)      (null)          (null)     (null)             (null)      (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)             (null)    (null)  (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)       2020-05-15 10:09:26  
937822197        0       MQOUTBREJ#BEANERROR  62           47           (null)           BZ.PV-I003  (null)           (null)         (null)       (null)        (null)        f1d0da3d-2431-4a32-b576-e104fd885f55  (null)          (null)      (null)          (null)     (null)             (null)      (null)                 (null)            (null)          (null)           (null)               (null)           (null)           (null)             (null)    (null)  (null)    (null)            (null)              (null)   (null)      (null)     (null)       (null)      (null)       2020-05-15 10:09:26 
*/
select * from vista.tsfmqinbound where jmscorrelationid='f1d0da3d-2431-4a32-b576-e104fd885f55'; -- EMPLOYEE;U;929844240;929844241;
select * from vista.tpvemployee where tpvemplid=929844240; -- tpvroleid: 929844237
select * from vista.tpvrole where tpvroleid=929844237; -- kpvroleid = 929844238, kpvpartid = 929837919 stimmt.
select * from vista.jpvemployee where tpvemplid=929844240; -- tpvroleid: 929844237
select distinct section from vista.tpvemployee;
select distinct cjobrole from vista.tpvemployee;
select distinct team from vista.tpvemployee;
select distinct clanguage from vista.tpvpartner;
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and date(lastupdated)>='2020-05-19' and outboundmsg like '%<ns2:lzPartnerKey>929837919</ns2:lzPartnerKey>%';
/*
TSFMQOUTBOUNDID  STATUS  REASON  EXECTIMEMDB  EXECTIMESRV  JMSMESSAGECLASS  JMSTYPE     JMSDELIVERYMODE  JMSEXPIRATION  JMSPRIORITY  JMSMESSAGEID                                         JMSTIMESTAMP   JMSCORRELATIONID                      JMSDESTINATION                                                                       JMSREPLYTO  JMSREDELIVERED  JMSXAPPID                     JMSXDELIVERYCOUNT  JMSXUSERID    JMS_IBM_CHARACTER_SET  JMS_IBM_ENCODING  JMS_IBM_FORMAT  JMS_IBM_MSGTYPE  JMS_IBM_PUTAPPLTYPE  JMS_IBM_PUTDATE  JMS_IBM_PUTTIME  BUSINESSPROCESSID  TENANTID  TOPIC                           USERNAME     USERLANGUAGECODE  INVALIDLETTERQUEUE  VERSION  SIMULATION  FAULTCODE  FAULTSTRING  FAULTACTOR  OUTBOUNDMSG                                                                                                                                                                                                                                                                                   LASTUPDATED          
---------------  ------  ------  -----------  -----------  ---------------  ----------  ---------------  -------------  -----------  ---------------------------------------------------  -------------  ------------------------------------  -----------------------------------------------------------------------------------  ----------  --------------  ----------------------------  -----------------  ------------  ---------------------  ----------------  --------------  ---------------  -------------------  ---------------  ---------------  -----------------  --------  ------------------------------  -----------  ----------------  ------------------  -------  ----------  ---------  -----------  ----------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -------------------  
939393206        0       (null)  125          47           JMSTextMessage   BZ.PV-I003  2                0              4            ID:414d51205453533147525020202020209dff775e271c9714  1589893779240  acb46e72-130b-4423-8fb4-02f6bdcd1274  queue:///LZPV.BZPV.I003.PARTNERDATA.REPLICATE?destDescription=pv+Replication+ReplyQ  (null)      0               bootstrap.WSPreLauncher       0                  svcmqplz0     (null)                 (null)            (null)          (null)           28                   20200519         13093949         (null)             GR        LZPV/BZPV/I003/Partner/Replica  GRPVMQINT01  (null)            (null)              5.0      (null)      (null)     (null)       (null)      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
*/

-- AIT:
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and date(lastupdated)='2020-05-18';
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and date(lastupdated)='2020-06-05'; -- working.



-- EduZH - TPVPARTNERREPLICATION
select * from vista.TPVDYNAMICPARAMS;
/*
TPVDYNPARAMID  PARAMNAME       PARAMVALUET          PARAMVALUES  LASTUPDATED          
-------------  --------------  -------------------  -----------  -------------------  
106071099      PVJREPLI_START  2020-05-18 14:00:21  (null)       2020-05-18 14:00:21  
663125152      PVJURCON_START  2020-05-15 00:00:00  (null)       2020-05-15 20:45:38  
*/
select * from vista.TPVPARTNERREPLICATION where lastupdated >= '2020-05-01 10:00:00' and lastupdated <= '2020-05-01 19:00:00'; -- empty

-- AHVZ: XML nicht vorhanden MQOUTINFO#IGNOREREPL Mail AndrÃ©, 25.05.2020
select * from vista.tsfmqinbound i where reason='MQOUTINFO#IGNOREREPL'; -- nichts in prodSG / ZH
select i.jmscorrelationid, o.jmscorrelationid, o.reason, o.jmstype, i.inboundmsg, o.outboundmsg from vista.tsfmqoutbound o 
join vista.tsfmqinbound i on (i.jmscorrelationid = o.jmscorrelationid)
where o.reason='MQOUTINFO#IGNOREREPL' and o.jmstype='BZ.PV-I003';
select * from vista.tpvpartner where kpvpartid in (2446493010);


-- ZAP: LZ.PV-RR002 - EDU NE
select * from vista.tsfmqoutbound; -- no privileges on eduNE
select * from vista.tpvpartner; -- no privileges
select * from vista.tsfmqoutbound where jmstype='LZ.PV-RR002'; -- working, 7 cases only
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, validfrom, validto from vista.tpvpartner where kpvpartid in (2302368, 2302386);
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME       ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  VALIDFROM   VALIDTO     
---------  ---------  ---------------------  ---------  --------------  ---------------  -----------  ----------  ----------  
101674432  2302368    1029441                NeuchÃ¢tel  (null)          NNPersonTy#POLG  458          1900-01-01  9999-12-31  
101674754  2302386    1029441                Valangin   (null)          NNPersonTy#POLG  485          1900-01-01  9999-12-31  
*/
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, validfrom, validto from vista.tpvpartner where kpvpartid in (1029441);
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME             ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  VALIDFROM   VALIDTO     
---------  ---------  ---------------------  ---------------  --------------  ---------------  -----------  -----------  ----------  ----------  
101602335  1029441    (null)                 ARAVS NeuchÃ¢tel  (null)          NNPersonTy#AHVZ  (null)       1            1900-01-01  9999-12-31  
*/
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, validfrom, validto from vista.tpvpartner where clegaltype='NNPersonTy#AHVZ';
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                            ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  VALIDFROM   VALIDTO     
---------  ---------  ---------------------  ------------------------------  --------------  ---------------  -----------  -----------  ----------  ----------  
101601626  1430314    (null)                 Prestation                      (null)          NNPersonTy#AHVZ  (null)       11           1900-01-01  9999-12-31  
101602335  1029441    (null)                 ARAVS NeuchÃ¢tel                 (null)          NNPersonTy#AHVZ  (null)       1            1900-01-01  9999-12-31  
101602358  1029443    (null)                 ARAVS Littoral Ouest            (null)          NNPersonTy#AHVZ  (null)       3            1900-01-01  9999-12-31  
101602362  1029444    (null)                 ARAVS Peseux                    (null)          NNPersonTy#AHVZ  (null)       4            1900-01-01  9999-12-31  
101602366  1029445    (null)                 ARAVS Corcelles-CormondrÃ¨che    (null)          NNPersonTy#AHVZ  (null)       5            1900-01-01  9999-12-31  
101602370  1029446    (null)                 ARAVS Val-de-Travers            (null)          NNPersonTy#AHVZ  (null)       6            1900-01-01  9999-12-31  
101602374  1029442    (null)                 ARAVS Entre-deux-Lacs           (null)          NNPersonTy#AHVZ  (null)       2            1900-01-01  9999-12-31  
101602378  1029447    (null)                 ARAVS Val-de-Ruz                (null)          NNPersonTy#AHVZ  (null)       7            1900-01-01  9999-12-31  
101602382  1029448    (null)                 ARAVS Montagnes NeuchÃ¢teloises  (null)          NNPersonTy#AHVZ  (null)       8            1900-01-01  9999-12-31  
101602403  1029449    (null)                 ARAVS La Chaux-de-Fonds         (null)          NNPersonTy#AHVZ  (null)       9            1900-01-01  9999-12-31  
101616047  1430812    (null)                 Agence AVS hors canton          (null)          NNPersonTy#AHVZ  (null)       999          1900-01-01  9999-12-31  
*/
select ahvz.tdmpvpartnerid, ahvz.ahvbranchnr, ahvz.clerkallocationcode, nh.orgname from migration.tdmpvahvz ahvz
left join migration.tdmpvorgnamehist nh on (nh.tdmpvpartnerid = ahvz.tdmpvpartnerid) where nh.validtill > current date;
/*
TDMPVPARTNERID                        AHVBRANCHNR  CLERKALLOCATIONCODE  ORGNAME                         
------------------------------------  -----------  -------------------  ------------------------------  
87133887-fc51-4bfd-adbc-ca211ceedaca  11           C                    Prestation                      
88aa030a-98be-2403-e040-0a0a2d0a1097  1            B                    ARAVS NeuchÃ¢tel                 
88aa030a-98c4-2403-e040-0a0a2d0a1097  2            B                    ARAVS Entre-deux-Lacs           
88aa030a-98cc-2403-e040-0a0a2d0a1097  3            B                    ARAVS Littoral Ouest            
88aa030a-98cd-2403-e040-0a0a2d0a1097  4            B                    ARAVS Peseux                    
88aa030a-98ce-2403-e040-0a0a2d0a1097  5            B                    ARAVS Corcelles-CormondrÃ¨che    
88aa030a-98cf-2403-e040-0a0a2d0a1097  6            B                    ARAVS Val-de-Travers            
88aa030a-98d0-2403-e040-0a0a2d0a1097  7            B                    ARAVS Val-de-Ruz                
88aa030a-98d1-2403-e040-0a0a2d0a1097  8            B                    ARAVS Montagnes NeuchÃ¢teloises  
88aa030a-98d2-2403-e040-0a0a2d0a1097  9            B                    ARAVS La Chaux-de-Fonds         
9108f2a9-961a-46d0-b64c-b082287b8e68  999          C                    Agence AVS hors canton          
*/
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, validfrom, validto from vista.tpvpartner where kpvpartid in (2302057, 2302058);

select par.kpvpartid, par.tpvpartid, par.kpvpartid_ahvbranchnr, par.name, par.clegaltype, par.ccanton, par.munauthornr, par.bfsmunitipalnr, par.extpartnerkey,
    zws.kpvpartid as zws_kpvpartid, zws.tpvpartid, zws.name, zws.clegaltype, zws.ahvbranchnr, zws.extpartnerkey
  from VISTA.tpvpartner par, VISTA.tpvpartner zws
WHERE par.clegaltype = 'NNPersonTy#POLG'
   AND CURRENT DATE >= par.validfrom
   AND CURRENT DATE <= par.validto
   and par.munauthornr is not null
   and par.kpvpartid_ahvbranchnr = zws.kpvpartid
   and current date >= zws.validfrom
   and current date <= zws.validto
   and zws.clegaltype = 'NNPersonTy#AHVZ'
ORDER BY zws.name, par.name;


-- MQOUTINFO#IGNOREREPL - André, 26.05.2020 - Initial-Update NE
/*
Wir haben AHVZ, die nicht repliziert wurden. Nun habe ich nach dem XML's gesucht, aber nichts gefunden.

Nach langem Suchen und Fluchen: ich finde dazu Einträge in der TSFMQINBOUND-Tabelle mit Reason MQOUTINFO#IGNOREREPL
Aber MQOUTINFO#IGNOREREPL sehe ich manchmal auch in der TSFMQOUTBOUND-Tabelle.

a)     Wann wird MQOUTINFO#IGNOREREPL gesetzt?
b)     Weshalb finde ich den Eintrag nur in der Inbound-Tabelle?

SIT-439:
2302406
2302400
2302669
2302668
2302821
*/
select kpvpartid, name, clegaltype, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid in (2302406, 2302400, 2302669, 2302668, 2302821, 2302847, 2303163, 2302846, 2303128, 2302692, 2303126);
/*
KPVPARTID  NAME                                      CLEGALTYPE     VALIDFROM   VALIDTO     LASTUPDATED          
---------  ----------------------------------------  -------------  ----------  ----------  -------------------  
2302406    AHV-Zweigstelle Biel/Bienne und Umgebung  NNPersonTy#AK  1900-01-01  2007-12-31  2020-05-13 15:16:36  
2302400    Ausgleichskasse Stadt Zürich              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:35  
2302669    Waadt (vermutlich aufgelöst)              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:15:47  
2302668    Waadt (aufgelöst, neu 22.132)             NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:27  
2302821    Gastrosocial (aufgelöst, neu 46.0)        NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:18:12  
2302847    Ausgleichskasse Engros-Möbel              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:35  
2303163    FRSP-CIRAV (aufgelöst, neu 106.1)         NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:17:15  
2302846    CIVAS (aufgelöst, neu 110.0)              NNPersonTy#AK  1900-01-01  1999-12-31  2020-05-13 15:15:48  
2303128    Ausgleichskasse Konfektion                NNPersonTy#AK  1900-01-01  1975-07-07  2020-05-13 15:16:39  
2302692    Ausgleichskasse ROTA                      NNPersonTy#AK  1900-01-01  1972-12-31  2020-05-13 15:16:39  
2303126    Ausgleichskasse Gerberei                  NNPersonTy#AK  1900-01-01  1968-12-23  2020-05-13 15:16:39  
*/
select * from vista.tsfmqinbound i where reason='MQOUTINFO#IGNOREREPL'; -- nichts in prodSG / ZH
select i.jmscorrelationid, o.jmscorrelationid, o.reason, o.jmstype, i.inboundmsg, o.outboundmsg from vista.tsfmqoutbound o 
join vista.tsfmqinbound i on (i.jmscorrelationid = o.jmscorrelationid)
where o.reason='MQOUTINFO#IGNOREREPL' and o.jmstype='BZ.PV-I003';
select * from vista.tpvpartner where kpvpartid in (2446493010);
select * from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' and o.lastupdated >= '2020-06-11' order by lastupdated desc;

select p.kpvpartid, p.name, p.clegaltype, p.validfrom, p.validto, p.lastupdated, a.kpvadrsid, a.caddresstype, a.validfrom, a.validto from vista.tpvpartner p 
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.caddresstype='AddressTyp#GS')
where p.kpvpartid in (2302406, 2302400, 2302669, 2302668, 2302821, 2302847, 2303163, 2302846, 2303128, 2302692, 2303126)
and (a.validto = (select max(amax.validto) from vista.tpvaddress amax where amax.kpvadrsid = a.kpvadrsid) or a.validto is null);
/*
KPVPARTID  NAME                                      CLEGALTYPE     VALIDFROM   VALIDTO     LASTUPDATED          KPVADRSID  CADDRESSTYPE   VALIDFROM   VALIDTO     
---------  ----------------------------------------  -------------  ----------  ----------  -------------------  ---------  -------------  ----------  ----------  
2302400    Ausgleichskasse Stadt Zürich              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:35  2412416    AddressTyp#GS  2009-08-24  2020-04-30  
2302406    AHV-Zweigstelle Biel/Bienne und Umgebung  NNPersonTy#AK  1900-01-01  2007-12-31  2020-05-13 15:16:36  2305592    AddressTyp#GS  2013-01-01  2020-04-30  
2302668    Waadt (aufgelöst, neu 22.132)             NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:27  (null)     (null)         (null)      (null)      
2302669    Waadt (vermutlich aufgelöst)              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:15:47  (null)     (null)         (null)      (null)      
2302692    Ausgleichskasse ROTA                      NNPersonTy#AK  1900-01-01  1972-12-31  2020-05-13 15:16:39  (null)     (null)         (null)      (null)      
2302821    Gastrosocial (aufgelöst, neu 46.0)        NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:18:12  (null)     (null)         (null)      (null)      
2302846    CIVAS (aufgelöst, neu 110.0)              NNPersonTy#AK  1900-01-01  1999-12-31  2020-05-13 15:15:48  (null)     (null)         (null)      (null)      
2302847    Ausgleichskasse Engros-Möbel              NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:16:35  (null)     (null)         (null)      (null)      
2303126    Ausgleichskasse Gerberei                  NNPersonTy#AK  1900-01-01  1968-12-23  2020-05-13 15:16:39  (null)     (null)         (null)      (null)      
2303128    Ausgleichskasse Konfektion                NNPersonTy#AK  1900-01-01  1975-07-07  2020-05-13 15:16:39  (null)     (null)         (null)      (null)      
2303163    FRSP-CIRAV (aufgelöst, neu 106.1)         NNPersonTy#AK  1900-01-01  2000-12-31  2020-05-13 15:17:15  (null)     (null)         (null)      (null)      
*/
select * from vista.TSFMQOUTBOUND where jmstype='BZ.PV-I003' and date(lastupdated)>='2020-05-13' and outboundmsg like '%<ns2:lzPartnerKey>2302406</ns2:lzPartnerKey>%'; -- exists!
select * from vista.TSFMQOUTBOUND where jmstype='BZ.PV-I003' and date(lastupdated)>='2020-05-13' and outboundmsg like '%<ns2:lzPartnerKey>2302668</ns2:lzPartnerKey>%'; -- empty.
select * from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' and o.lastupdated >= '2020-06-11' order by lastupdated desc;
select * from vista.tsfmqinbound i where i.jmstype='BZ.PV-I003' and i.lastupdated >= '2020-06-11' order by lastupdated desc;
select * from vista.TSFMQEVENT e where e.lastupdated >= '2020-06-11' order by lastupdated desc;
/*
TSFMQEVENTID  CREATED              PRIORITY  STATUS  APPLICATION  TRIGGEROBJECT  ACTION  KEY1       KEY2     LASTUPDATED          
------------  -------------------  --------  ------  -----------  -------------  ------  ---------  -------  -------------------  
1018662904    2020-06-11 12:55:52  4         1       PV           PARTNER        U       101532547  2303163  2020-06-11 12:58:53  
*/
update vista.tpvpartner set lastupdated=current timestamp where kpvpartid=2303163;
select tsfmqoutboundid, status, reason, jmstype, jmscorrelationid,outboundmsg, lastupdated from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' and o.lastupdated >= '2020-06-11' order by lastupdated desc;


-- KEP
select birthdateprec, count(*) from vista.tpvpartner group by birthdateprec ;
select * from vista.tpvaddress;
select * from vista.tpvpartner where cresidauthor is not null;


-- 231319 - SZ - Todesfallmeldung fehlt
/*
-- SO (nicht SZ)
TBCBATCHCTRLID  TBCBATCHRUNID  APPLICATION  BATCHID   STARTTIME            ENDTIME              RUNTIME_MINUTES  STATE  RETURNCODE         CALCULATED  BCOK
--------------  -------------  -----------  --------  -------------------  -------------------  ---------------  -----  -----------------  ----------  ----
998980751       998980752      PV           PVJURCON  2020-05-18 20:31:57  2020-05-18 20:32:25  0                ENDED  BR_OK              237         237 
999334489       999334490      PV           PVJURCON  2020-05-19 20:31:48  2020-05-19 20:32:12  0                ENDED  BR_OK              176         176 
999713012       999713013      PV           PVJURCON  2020-05-20 20:32:17  2020-05-20 20:32:41  0                ENDED  BR_OK              167         167 
1000121000      1000121001     PV           PVJURCON  2020-05-22 20:33:51  2020-05-22 20:34:14  0                ENDED  BR_OK              171         171 
1000492303      1000492304     PV           PVJURCON  2020-05-25 20:29:40  2020-05-25 20:29:52  0                ENDED  BR_OK_NO_WORKLOAD  0           0   
1001471425      1001471426     PV           PVJURCON  2020-05-26 20:33:42  2020-05-26 20:34:04  0                ENDED  BR_OK              170         170 
1001769054      1001769055     PV           PVJURCON  2020-05-27 21:45:40  2020-05-27 21:46:19  0                ENDED  BR_OK              167         167 
1002238972      1002238973     PV           PVJURCON  2020-05-28 20:29:10  2020-05-28 20:29:35  0                ENDED  BR_OK              159         159 
1002974382      1002974383     PV           PVJURCON  2020-05-29 20:50:44  2020-05-29 20:51:08  0                ENDED  BR_OK              174         174 
1005374999      1005375000     PV           PVJURCON  2020-06-02 20:33:16  2020-06-02 20:33:42  0                ENDED  BR_OK              157         157 
1006953864      1006953865     PV           PVJURCON  2020-06-03 22:45:58  2020-06-03 22:46:12  0                ENDED  BR_OK_NO_WORKLOAD  0           0   
1007564539      1007564540     PV           PVJURCON  2020-06-04 21:14:11  2020-06-04 21:14:40  0                ENDED  BR_OK              131         131 
1010016546      1010016547     PV           PVJURCON  2020-06-05 20:34:57  2020-06-05 20:35:23  0                ENDED  BR_OK              191         191

-- SZ:
TBCBATCHCTRLID  TBCBATCHRUNID  APPLICATION  BATCHID   STARTTIME            ENDTIME              RUNTIME_MINUTES  STATE  RETURNCODE         CALCULATED  BCOK
--------------  -------------  -----------  --------  -------------------  -------------------  ---------------  -----  -----------------  ----------  ----
709075461       709075462      PV           PVJURCON  2020-05-18 20:43:53  2020-05-18 20:44:21  0                ENDED  BR_OK              140         140 
709317563       709317564      PV           PVJURCON  2020-05-19 20:43:02  2020-05-19 20:43:28  0                ENDED  BR_OK              131         131 
709571456       709571457      PV           PVJURCON  2020-05-20 20:44:32  2020-05-20 20:44:58  0                ENDED  BR_OK              114         114 
709852520       709852521      PV           PVJURCON  2020-05-22 20:43:33  2020-05-22 20:44:01  0                ENDED  BR_OK              116         116 
710938791       710938792      PV           PVJURCON  2020-05-25 20:40:27  2020-05-25 20:40:40  0                ENDED  BR_OK_NO_WORKLOAD  0           0   
711206372       711206373      PV           PVJURCON  2020-05-26 20:44:11  2020-05-26 20:44:36  0                ENDED  BR_OK              152         152 
711429966       711429967      PV           PVJURCON  2020-05-27 21:48:41  2020-05-27 21:49:27  0                ENDED  BR_OK              124         124 
711664556       711664557      PV           PVJURCON  2020-05-28 20:40:40  2020-05-28 20:41:04  0                ENDED  BR_OK              135         135 
712105850       712105854      PV           PVJURCON  2020-05-29 20:47:10  2020-05-29 20:47:45  0                ENDED  BR_OK              125         125 
713011763       713011764      PV           PVJURCON  2020-06-02 20:43:16  2020-06-02 20:43:41  0                ENDED  BR_OK              164         164 
713683374       713683375      PV           PVJURCON  2020-06-03 22:47:32  2020-06-03 22:47:47  0                ENDED  BR_OK_NO_WORKLOAD  0           0   
714172750       714172751      PV           PVJURCON  2020-06-04 21:13:43  2020-06-04 21:14:15  0                ENDED  BR_OK              135         135 
715648388       715648389      PV           PVJURCON  2020-06-05 20:43:05  2020-06-05 20:43:30  0                ENDED  BR_OK              120         120 
(...)
717119960       717119961      PV           PVJURCON  2020-06-12 20:42:06  2020-06-12 20:42:28  0                ENDED  BR_OK              93          93  
717741506       717741507      PV           PVJURCON  2020-06-15 20:42:00  2020-06-15 20:42:23  0                ENDED  BR_OK              110         110 
717951646       717951647      PV           PVJURCON  2020-06-16 20:43:09  2020-06-16 20:43:35  0                ENDED  BR_OK              139         139 

-- SG:
TBCBATCHCTRLID  TBCBATCHRUNID  APPLICATION  BATCHID   STARTTIME            ENDTIME              RUNTIME_MINUTES  STATE  RETURNCODE                  CALCULATED  BCOK
--------------  -------------  -----------  --------  -------------------  -------------------  ---------------  -----  --------------------------  ----------  ----
2448702538      2448702539     PV           PVJURCON  2020-05-18 20:43:49  2020-05-18 20:44:31  0                ENDED  BR_OK                       428         428 
2449409884      2449409885     PV           PVJURCON  2020-05-19 20:38:26  2020-05-19 20:38:58  0                ENDED  BR_OK_WITH_WORKITEM_ERRORS  436         435 
2449990835      2449990836     PV           PVJURCON  2020-05-20 20:40:59  2020-05-20 20:41:34  0                ENDED  BR_OK_WITH_WORKITEM_ERRORS  425         424 
2450585191      2450585192     PV           PVJURCON  2020-05-22 20:40:25  2020-05-22 20:41:05  0                ENDED  BR_OK_WITH_WORKITEM_ERRORS  435         434 
2453438768      2453438769     PV           PVJURCON  2020-05-25 20:36:56  2020-05-25 20:37:09  0                ENDED  BR_OK_NO_WORKLOAD           0           0   
2454296320      2454296321     PV           PVJURCON  2020-05-26 20:42:24  2020-05-26 20:42:57  0                ENDED  BR_OK_WITH_WORKITEM_ERRORS  403         402 
2454807135      2454807136     PV           PVJURCON  2020-05-27 21:58:21  2020-05-27 21:59:01  0                ENDED  BR_OK                       410         410 
2455260644      2455260645     PV           PVJURCON  2020-05-28 20:30:19  2020-05-28 20:30:55  0                ENDED  BR_OK                       402         402 
2456295079      2456295080     PV           PVJURCON  2020-05-29 21:09:14  2020-05-29 21:09:50  0                ENDED  BR_OK                       393         393 
2458751469      2458751474     PV           PVJURCON  2020-06-02 20:49:25  2020-06-02 20:50:00  0                ENDED  BR_OK_WITH_WORKITEM_ERRORS  430         429 
2462245606      2462245607     PV           PVJURCON  2020-06-03 22:54:00  2020-06-03 22:54:14  0                ENDED  BR_OK_NO_WORKLOAD           0           0   
2462668879      2462668882     PV           PVJURCON  2020-06-04 21:19:33  2020-06-04 21:20:14  0                ENDED  BR_OK                       395         395 
2463217392      2463217393     PV           PVJURCON  2020-06-05 20:39:44  2020-06-05 20:40:23  0                ENDED  BR_OK                       390         390 
*/
select * from vista.tpvpartner where personid='7565376094112';
select * from vista.jpvpartner where personid='7565376094112'; -- PV:PV-Dlg-20104 Dialog Todesdatum erfassen @2020-06-18 09:11:45
select * from vista.aurupiregister where new_nnss='7565376094112';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  --------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1697309972        52739416116      7565376094112  0         0            KAELIN,FRANZ          1         16101939  100            (null)    (null)     (null)         (null)             (null)             (null)         2020-06-14 20:15:51  
1721434509        7565376094112    7565376094112  0         0            KAELIN,FRANZ ANDREAS  1         16101939  100            950000    (null)     (null)         (null)             (null)             (null)         2020-06-14 20:15:51  
1721434510        7565376094112    7565376094112  0         0            KAELIN,FRANZ ANDREAS  1         16101939  100            970000    (null)     (null)         (null)             (null)             (null)         2020-06-14 20:15:51  
1721434508        7565376094112    7565376094112  0         1            KAELIN,FRANZ ANDREAS  1         16101939  100            950000    30052020   2              (null)             24101969           (null)         2020-06-14 20:15:51  
*/
select min(lastupdated), max(lastupdated) from vista.aurupiregister;
/*
1                    2                    
-------------------  -------------------  
2020-06-14 20:15:51  2020-06-22 20:17:02  
*/
select min(delivery_date) as min_dd, max(delivery_date) as max_dd from vista.aurupiregister;
/*
MIN_DD      MAX_DD      
----------  ----------  
2020-06-03  2020-06-19   
*/
select * from vista.tpvdynamicparams;

-- KEP
select * from vista.tpvrolerel where crelationtype='RoleRelati#GV';
select * from vista.tpvfamilyrel;

-- test data
-- kpvpartid: 200000000
insert into vista.kpvpartner (kpvpartid) values (?);
insert into vista.tpvpartner (tpvpartid, kpvpartid, cpartnertype, name, firstname, clanguage, birthdate, birthdateprec, csex, personid, deathdate, validfrom, validto) values
;

-- 231625 - LI - High - Mutationen nicht mehr möglich
select * from vista.jpvpartner where change_date >= '2020-06-04';
select program, count(*) as cnt_prg from vista.jpvpartner where change_date >= '2020-06-25' group by program order by 2 desc; -- total
/*
PROGRAM                                          CNT_PRG  
-----------------------------------------------  -------  
PV:PV-Dlg-201 Person                             148      
PV:PV-Dlg-701 Dialog Periode Person              52       
IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e          48       
PV:PV-Dlg-20300 Nichtnatuerliche Person          15       
PV:PV-Dlg-20104 Dialog Todesdatum erfassen       10       
PV:PV-Dlg-20102 Dialog Scheidungsdatum erfassen  4        
IK:APP129_IK-Dlg-008_IK-Mutation_e               2            
*/
select change_user, count(*) as cnt_user from vista.jpvpartner where change_date >= '2020-06-25' and program='PV:PV-Dlg-701 Dialog Periode Person' group by change_user order by 2 desc; -- total
/*
CHANGE_USER  CNT_USER  
-----------  --------  
lijute       4         
licola       2               
*/
select * from vista.jpvpartner where personid='14462';
select * from vista.tpvpartner;
select * from vista.tpvaddressbasic;
select * from vista.tpvaddress;

select * from vista.tpvrolerel;


-- 232432 - TG - Pro Rolle und Korrespondenzempfänger-Art [KorrespArt] nicht mehr als einen Eintrag geben - 756.7410.9019.98 Widmer Stephanie
select rr1.kpvroleid_source, rr1.kpvroleid_target, count(distinct rr1.kpvrrelid) as cnt_reks from vista.tpvrolerel rr1
left join vista.tpvrolerel rr2 on (
    rr2.kpvroleid_source = rr1.kpvroleid_source and rr1.kpvroleid_target = rr2.kpvroleid_target 
    and rr2.kpvrrelid <> rr1.kpvrrelid and rr1.ccorraddresseetype = rr2.ccorraddresseetype
    and rr1.validto >= current date
)
where rr1.ccorraddresseetype = 'Correspond#REK' 
and rr1.validto >= current date
group by rr1.kpvroleid_source, rr1.kpvroleid_target
having count(distinct rr1.kpvrrelid) > 1
order by 3 desc;
/*
empty
*/
SELECT * FROM vista.TPVROLE t
LEFT JOIN vista.tpvrolerel tr ON t.KPVROLEID IN (tr.KPVROLEID_SOURCE, tr.KPVROLEID_TARGET)
WHERE t.KPVPARTID=2859278 AND tr.CRELATIONTYPE='RoleRelati#KE' AND tr.CCORRADDRESSEETYPE='Correspond#REK';

select * from vista.tpvrolerel where kpvroleid_source=680070107 and ccorraddresseetype = 'Correspond#REK' order by kpvroleid_target;

select * from vista.tpvrolerel where kpvroleid_source=932019939 and ccorraddresseetype = 'Correspond#REK' order by kpvroleid_target;
select * from vista.tpvrolerel where kpvroleid_source=932019939 and ccorraddresseetype is not null order by kpvroleid_target;

select * from vista.tpvparticipatorrel;
/*
TPVPCPTID  KPVPARTID  KPVROLEID  CRELATIONTYPE   RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ---------  ---------  --------------  -------------  -----------  -------------------  
44022095   25617784   44022094   JointPartn#KOL  1996-09-03     9999-12-31   2008-10-23 17:20:20  
44022099   25617784   44022098   JointPartn#KOL  1996-09-03     9999-12-31   2008-10-23 17:20:20  
*/
select distinct t.kpvpartid, t.kpvroleid, t.crelationtype, p.name, p.additionalname, r.croletype, p2.kpvpartid as teil_kpvpartid, p2.name as teil_name from vista.tpvparticipatorrel t
left join vista.tpvpartner p on (p.kpvpartid = t.kpvpartid)
left join vista.tpvrole r on (r.kpvroleid = t.kpvroleid)
left join vista.tpvpartner p2 on (p2.kpvpartid = r.kpvpartid and p2.validto >= current date);
/*
KPVPARTID  KPVROLEID  CRELATIONTYPE   NAME                           ADDITIONALNAME            CROLETYPE  TEIL_KPVPARTID  TEIL_NAME  
---------  ---------  --------------  -----------------------------  ------------------------  ---------  --------------  ---------  
25617784   44022094   JointPartn#KOL  Agora Education, Training and  Consulting, Salathé + Co  Rolle#TEI  14658276        Frei       
25617784   44022098   JointPartn#KOL  Agora Education, Training and  Consulting, Salathé + Co  Rolle#TEI  14697335        Salathé    
*/

select * from vista.TSFMQEVENT;
select * from vista.tpvpartner where companynr is not null;

select * from vista.tiscmcode where code_id like '%ZAMSGTYPE#2469-201%';

select * from vista.tikkoaurequest;
select * from vista.tsfmqevent;

-- Ticket 233911 - ZH - Ausländische IBAN nicht mutierbar
select * from vista.tpvpartner where kpvpartid=393210257;
select * from vista.tpvpaymentaddr where kpvpartid=393210257;
/*
TPVPADDID   KPVPARTID  KPVPADDID   KPVBANKID  CPAYTYPE      ACCOUNT  IBAN    CCOUNTRY  ACCOUNTHOLDER  VALIDFROM   VALIDTO     KPVADRSID   SAPNR  CBORDEREAU  EXTACCOUNTKEY  LASTUPDATED          
----------  ---------  ----------  ---------  ------------  -------  ------  --------  -------------  ----------  ----------  ----------  -----  ----------  -------------  -------------------  
1403194056  393210257  1403194057  (null)     TypePaymen#Z  (null)   (null)  (null)    (null)         2014-09-11  9999-12-31  1403192683  1      (null)      (null)         2014-09-11 14:09:59  
*/

-- UID
select tikearcid, billnbr, uid, adr1, validfrom, validto from vista.tikemployerarchive;


-- KOUB printing
select * from vista.tikheader where vnr='7560014942077'; -- 1070039
select * from vista.tikbookingdelivered; -- where vnr='7560014942077';
select * from vista.tikzikexecution where vnr='7560014942077';
/*
TIKZEXCID  TIKZIORID  TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME        BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
---------  ---------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  -------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
11408149   11408148   (null)           (null)           (null)            2020-08-13        0            1                    17     0      7560014942077  STAUB_IK,RUTH  0                        0                      0               2020-08-13     SGLOGIN     1          2020-08-13    (null)                        2020-08-13 12:01:45  
11410196   11410195   (null)           (null)           (null)            2020-08-13        0            1                    17     0      7560014942077  STAUB_IK,RUTH  0                        0                      0               2020-08-13     SGLOGIN     1          2020-08-13    (null)                        2020-08-13 12:42:23  
*/
select * from vista.tikbookingdelivered where tikzexcid in (11408149, 11410196); 
/*
TIKBODVID  TIKZEXCID  TIKBOPEID  TIKEXECPROVID  BILLZIP  BILLDESCR             INCOME  BILLNBR        CCONTRIBUTIONTYPE  CBUSINESSSECTOR  CCARETAKINGFACTOR  CSPECIALCASE  CAMORTISATIONCODE  CSTORNOCODE  LASTUPDATED          
---------  ---------  ---------  -------------  -------  --------------------  ------  -------------  -----------------  ---------------  -----------------  ------------  -----------------  -----------  -------------------  
11408151   11408149   11408150   (null)         900000   Hase Fuchs AG         300.00  2670677        SZBEITRART#1       BRANCHE#10       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408154   11408149   11408153   (null)         900000   Hase Fuchs AG         300.00  2670677        SZBEITRART#1       BRANCHE#10       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408157   11408149   11408156   (null)         809000   Kantonale Verwaltung  600.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408160   11408149   11408159   (null)         809000   Kantonale Verwaltung  455.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408163   11408149   11408162   (null)         809000   Kantonale Verwaltung  400.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408166   11408149   11408165   (null)         809000   Kantonale Verwaltung  350.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408169   11408149   11408168   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408172   11408149   11408171   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11408175   11408149   11408174   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:01:45  
11410198   11410196   11410197   (null)         900000   Hase Fuchs AG         300.00  2670677        SZBEITRART#1       BRANCHE#10       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410201   11410196   11410200   (null)         900000   Hase Fuchs AG         300.00  2670677        SZBEITRART#1       BRANCHE#10       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410204   11410196   11410203   (null)         809000   Kantonale Verwaltung  600.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410207   11410196   11410206   (null)         809000   Kantonale Verwaltung  455.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410210   11410196   11410209   (null)         809000   Kantonale Verwaltung  400.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410213   11410196   11410212   (null)         809000   Kantonale Verwaltung  350.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410216   11410196   11410215   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410219   11410196   11410218   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
11410222   11410196   11410221   (null)         809000   Kantonale Verwaltung  300.00  651133         SZBEITRART#1       BRANCHE#60       (null)             (null)        (null)             SZSTORNO#0   2020-08-13 12:42:23  
*/
select * from vista.tikaccount where tikheadid=1070039;
/*
TIKACCTID  TIKHEADID  CACCOUNTTYPE  CREATIONYEAR  CCREATIONREASON  AKNOTICE  CSTATE      CZIKREASON  ZIKAK   ZIKBO   ZIKCLOSINGDATE  LASTUPDATED          
---------  ---------  ------------  ------------  ---------------  --------  ----------  ----------  ------  ------  --------------  -------------------  
1070039    1070039    ACCTYPE#IK    2007          SZMZR#21         LADINS    IKSTATUS#O  (null)      (null)  (null)  (null)          2006-02-16 09:26:58  
*/
select * from vista.tikbooking where tikacctid=1070039;
/*
TIKBOOKID  TIKBOOKID_STORNO  TIKACCTID  TIKBOPEID  TIKINRETID  TIKBOOKID_REBOOKED  TIKCTCAID  BNOCHECKCODE  BOOKINGDATE  BILLNBR      INCOME  CCONTRIBUTIONTYPE  CCARETAKINGFACTOR  NBRINSURED  PENDVNR  PENDNAME  PENDFIRSTNAME  CEMPLOYEECODE  BASYLUMCODE  BWRITEOFFCODE  BPROVCODE  BPAPERIK  NBRAK  NBRBO  BSUPPRESSEDBOOKING  SPOUSEVNR  BMANSPLITTBOOKFLTIMES  BOOKEDBY  CLASTACTION   IKLASTACTIONDATE  IKLASTACTIONBY  BPENSIONZIK  CSTORNOCODE  BIEDV2000ID       CSPECIALCODE  CCODEADS  CSECTOR  CTOWNSHIP  BWDECREEOID  BWLISTOID  BWENTRYOID  PROCESSID  LASTUPDATED          
---------  ----------------  ---------  ---------  ----------  ------------------  ---------  ------------  -----------  -----------  ------  -----------------  -----------------  ----------  -------  --------  -------------  -------------  -----------  -------------  ---------  --------  -----  -----  ------------------  ---------  ---------------------  --------  ------------  ----------------  --------------  -----------  -----------  ----------------  ------------  --------  -------  ---------  -----------  ---------  ----------  ---------  -------------------  
1052526    (null)            1070039    1050260    (null)      (null)              (null)     0             1991-07-25   651133       300.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      bc        IKBUCHHIST#n  1991-07-25        bc              0            SZSTORNO#0   1000000000212239  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057183    (null)            1070039    1050261    (null)      (null)              (null)     0             1991-07-25   651133       300.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      bc        IKBUCHHIST#n  1991-07-25        bc              0            SZSTORNO#0   1000000000212240  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057184    (null)            1070039    1050262    (null)      (null)              (null)     0             1991-07-25   651133       300.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      bc        IKBUCHHIST#n  1991-07-25        bc              0            SZSTORNO#0   1000000000212241  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057185    (null)            1070039    1050263    (null)      (null)              (null)     0             2006-07-25   Q70677       300.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      bc        IKBUCHHIST#n  2006-07-25        bc              0            SZSTORNO#0   1000000000212242  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057186    (null)            1070039    1050264    (null)      (null)              (null)     0             2006-07-26   Q70677       300.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      bc        IKBUCHHIST#n  2006-07-26        bc              0            SZSTORNO#0   1000000000212243  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057475    (null)            1070039    1050265    (null)      (null)              (null)     0             1991-07-26   651133       350.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      kann      IKBUCHHIST#n  1991-07-26        kann            0            SZSTORNO#0   1000000000212244  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057476    (null)            1070039    1050266    (null)      (null)              (null)     0             1991-07-27   651133       400.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      kann      IKBUCHHIST#n  1991-07-27        kann            0            SZSTORNO#0   1000000000212245  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057477    (null)            1070039    1050267    (null)      (null)              (null)     0             1991-07-28   651133       455.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      kann      IKBUCHHIST#n  1991-07-28        kann            0            SZSTORNO#0   1000000000212246  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
1057478    (null)            1070039    1050268    (null)      (null)              (null)     0             1991-07-29   651133       600.00  SZBEITRART#1       (null)             0           (null)   (null)    (null)         YESNO#J        0            0              0          1         1      0      0                   (null)     0                      kann      IKBUCHHIST#n  1991-07-29        kann            0            SZSTORNO#0   1000000000212247  (null)        (null)    (null)   (null)     (null)       (null)     (null)      (null)     2006-02-16 09:26:58  
*/
select * from vista.tikperiod where tikbopeid in (1050260);
/*
TIKBOPEID  ENDDATE  BEGINDATE  NBRMONTHS  REFYEAR  CSPECIALITY    ENDMONTH  BEGINMONTH  TYPE  LASTUPDATED          
---------  -------  ---------  ---------  -------  -------------  --------  ----------  ----  -------------------  
1050260    (null)   (null)     0          1961     IKBEITRBES#00  (null)    (null)      3     2006-02-16 09:26:58  
*/
select * from vista.tikperiod where tikbopeid in (1050268);
select * from vista.tikemployerarchive where billnbr='651133';
select * from vista.tikzikrequest order by lastupdated desc;
select * from vista.tikzikorder order by lastupdated desc; -- newly generated


insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1970, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, '1970-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', '1970-01-01', 'gebr', 0, 'SZSTORNO#0', 9000000000000000, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1971, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, '1971-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', '1971-01-01', 'gebr', 0, 'SZSTORNO#0', 9000000000000001, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1972, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, '1972-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', '1972-01-01', 'gebr', 0, 'SZSTORNO#0', 9000000000000002, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1973, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, '1973-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', '1973-01-01', 'gebr', 0, 'SZSTORNO#0', 9000000000000003, null, null, null, null, null, null, null, null, current timestamp);

insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1973, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1973-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1973-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000003, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1974, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1974-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1974-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000004, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1975, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1975-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1975-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000005, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1976, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1976-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1976-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000006, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1977, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1973-01-07', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1973-01-07', 'gebr', 0, 'SZSTORNO#0', 
9000000000000007, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1978, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1978-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1978-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000008, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1979, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1979-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1979-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000009, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1980, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1980-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1980-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000080, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1981, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1981-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1981-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000081, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1982, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1982-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1982-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000082, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1983, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1983-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1983-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000083, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1984, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1984-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1984-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000084, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1985, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1985-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1985-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000080, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1980, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1986-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1986-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000086, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1987, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1987-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1987-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000087, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1988, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1988-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1988-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000088, null, null, null, null, null, null, null, null, current timestamp);
insert into vista.tikperiod values (next value for vista.vista_seq, null, null, 0, 1989, 'IKBEITRBES#00', null, null, 3, current timestamp);
insert into vista.tikbooking values (next value for vista.vista_seq, null, 1070039, (select max(tikbopeid) from vista.tikperiod), null, null, null, 0, 
'1989-01-01', '651133', 9999.00, 'SZBEITRART#1', null, 0, null, null, null, 'YESNO#J', 0, 0, 0 ,1, 1, 0, 0, null, 0, 'gebr', 'IKBUCHHIST#n', 
'1989-01-01', 'gebr', 0, 'SZSTORNO#0', 
9000000000000089, null, null, null, null, null, null, null, null, current timestamp);

delete from vista.tikbooking where lastupdated >= '2020-08-13';
delete from vista.tikbookingdelivered where lastupdated >= '2020-08-13';
delete from vista.tikperiod where lastupdated >= '2020-08-13';

-- Krishan: 969.42.761.144
select * from vista.TIKZIKEXECUTION where TIKZEXCID = '1060001'; -- just replaced the TIKZEXCID of other booking in the bookingdelivered table with  1060001;

select * from vista.tpvpartner where personid is not null and cresidauthor is not null;
select distinct croletype from vista.tpvrole;

select distinct a1.kpvpartid, p1.name, a1.caddresstype, p1.cpartnertype, a2.kpvadrsid
from vista.tpvaddress a1
left join vista.tpvaddress a2 on (a2.kpvpartid = a1.kpvpartid and a2.kpvadrsid <> a1.kpvadrsid)
left join vista.tpvpartner p1 on (p1.kpvpartid = a1.kpvpartid and p1.validto > current date)
where a1.caddresstype='AddressTyp#ZA' and a2.caddresstype='AddressTyp#ZA' and a1.validto > current date and a2.validto > current date and p1.cpartnertype like '%#NP';

select count(distinct a1.kpvadrsid)
from vista.tpvaddress a1
left join vista.tpvaddress a2 on (a2.kpvpartid = a1.kpvpartid and a2.kpvadrsid <> a1.kpvadrsid)
left join vista.tpvpartner p1 on (p1.kpvpartid = a1.kpvpartid and p1.validto > current date)
where a1.caddresstype='AddressTyp#ZA' and a2.caddresstype='AddressTyp#ZA' and a1.validto > current date and a2.validto > current date and p1.cpartnertype like '%#NP';
-- 7045
select count(distinct p1.kpvpartid)
from vista.tpvaddress a1
left join vista.tpvaddress a2 on (a2.kpvpartid = a1.kpvpartid and a2.kpvadrsid <> a1.kpvadrsid)
left join vista.tpvpartner p1 on (p1.kpvpartid = a1.kpvpartid and p1.validto > current date)
where a1.caddresstype='AddressTyp#ZA' and a2.caddresstype='AddressTyp#ZA' and a1.validto > current date and a2.validto > current date and p1.cpartnertype like '%#NP';
-- 3285

select distinct(gendercd) from vista.aurupiregister;

select * from vista.tpvpartner where name='Cc Verom'; -- 856949
select * from vista.tpvrole where kpvpartid=856949;
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
856957     856958     856949     Rolle#STA  (null)     (null)       (null)  1948-01-01  9999-12-31  2009-06-03 20:08:32  
53077706   53077707   856949     Rolle#EMP  (null)     (null)       (null)  2012-08-14  9999-12-31  2012-08-14 09:03:41 --> KE-RoleRel auf EL 
*/
select * from vista.tpvrolerel where kpvroleid_source in (856958, 53077707) or kpvroleid_target in (856958, 53077707);
/*
TPVRRELID  KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVPADDID  KPVRRELID  KPVADRSID_CORR  KPVADRSID_MAIL  KPVPARTID_ADDRESSEE2  CRELATIONTYPE  CLEGALGUARDTYPE  CPAYADDRESSEETYPE  CONTACTPERSON  CCONTACTPERSONSALUT  VALIDFROM   VALIDTO     CCORRADDRESSEETYPE  MANUALLETTERSALUT                 MANUALLETTERSALUT2  REFERENCENR  LASTUPDATED          
---------  ----------------  ----------------  ---------  ---------  --------------  --------------  --------------------  -------------  ---------------  -----------------  -------------  -------------------  ----------  ----------  ------------------  --------------------------------  ------------------  -----------  -------------------  
53077708   53077707          856958            (null)     53077709   1029970         (null)          (null)                RoleRelati#KE  (null)           (null)             (null)         (null)               2012-08-14  2020-08-31  Correspond#ELDO     Gentile signora, egregio signore  (null)              (null)       2020-08-31 12:11:08  
*/
select * from vista.tpvaddress where kpvadrsid=1029970; -- kpvpartid=856949 (eigener Partner)

-- KEP
-- SIT401:
Select * from vista.TZAXMLSDXRECORD
where date(lastupdated) >= current date
and MESSAGETYPE = '10099'
and STATE = '2';

Select * from vista.TZAXMLSDXRECORD where MESSAGETYPE = '10099' fetch first 10 rows only;
select * from vista.tpvkepprocessing;
select ismainpartner, count(*) as cnt_p from vista.tpvkeppartner group by ismainpartner; -- 1699

-- 
select * from vista.tikinsurancerequest vaikr, vista.tikvaikrequest vaik
where vaikr.printorderdate is not null
and vaikr.tikviooid = vaik.tikviooid
and ((bprintinsuranceproof = 1 and insuranceproofprintdate is null)
or (bprintinsurancecert = 1 and insurancecertprintdate is null));
/*
TIKVIOOID   CUSTOMER    CORRESPONCEADDRESSID  BPRINTID  BZASCOMPLETED  PRINTORDERDATE  VISTADOCREF          LASTUPDATED          TIKVAIKREQID  KPVROLEID   TIKVIOOID   DELIVERYADDRESSIK  DELIVERYADDRESSPK  CSZ       AKNOTICE          REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CPENDPROTECTIONCODE  BHASALREADYIK  BILLNO    ENTRYDATE  INSURANCEPROOFPRINTDATE  INSURANCECERTPRINTDATE  BPRINTINSURANCEPROOF  BPRINTINSURANCECERT  PRINTINGLANGUAGE  LASTUPDATED          
----------  ----------  --------------------  --------  -------------  --------------  -------------------  -------------------  ------------  ----------  ----------  -----------------  -----------------  --------  ----------------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -------------------  -------------  --------  ---------  -----------------------  ----------------------  --------------------  -------------------  ----------------  -------------------  
2528924209  281852018   281852054             0         0              2020-09-07      VDR4811500020615178  2020-09-07 20:40:58  2528926949    2528926944  2528924209  (null)             281852054          SZMZR#11  SGFA/P33.743      2020-09-04   823080  2020-09-04        2020-09-04      MZRFEHLER#2      (null)                sgfa       Protection#0         (null)         P33743    (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-09-07 20:25:16  
2532468820  281852018   281852054             0         0              2020-09-11      VDR5413210020647748  2020-09-11 20:47:57  2532469014    2532469009  2532468820  (null)             281852054          SZMZR#11  SGFA/P33.743      2020-09-10   826200  2020-09-10        2020-09-10      MZRFEHLER#2      (null)                sgfa       Protection#0         (null)         P33743    (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-09-11 20:26:38  
2535461972  1445402200  12155978              0         0              2020-09-16      VDR5913490020671510  2020-09-16 22:22:00  2535462283    2535462201  2535461972  (null)             12155978           SZMZR#11  SGLIA/10.023.469  2020-09-15   826901  2020-09-15        2020-09-15      MZRFEHLER#2      (null)                sglia      Protection#0         (null)         10023469  (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-09-16 22:03:56  
2535463953  672073798   672073808             0         0              2020-09-16      VDR5913530020671518  2020-09-16 22:22:00  2535465124    2535465119  2535463953  (null)             672073808          SZMZR#11  SGLIA/S96.058     2020-09-15   826903  2020-09-15        2020-09-15      MZRFEHLER#2      (null)                sglia      Protection#0         (null)         S96058    (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-09-16 22:04:02  
2535808799  503455564   503455638             0         0              2020-09-17      VDR6008340020675830  2020-09-17 20:27:05  2535809039    2535809034  2535808799  (null)             503455638          SZMZR#11  SGFA/R17.627      2020-09-16   826992  2020-09-16        2020-09-16      MZRFEHLER#2      (null)                sgfa       Protection#0         (null)         R17627    (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-09-16 22:04:25  
2560204509  10795277    291329321             0         0              2020-10-01      VDR7412120020751513  2020-10-01 20:41:50  2560212767    2560212762  2560204509  (null)             291329321          SZMZR#11  SGFA/G58.269      2020-09-30   828840  2020-09-30        2020-09-30      MZRFEHLER#2      (null)                sgfa       Protection#0         (null)         G58269    (null)     (null)                   (null)                  0                     1                    CorresLang#D      2020-10-01 20:28:26  
*/
select vaikr.*, vaik.* from vista.tikinsurancerequest vaikr
join vista.tikvaikrequest vaik on (vaikr.tikviooid = vaik.tikviooid)
where vaikr.printorderdate is not null
and ((bprintinsuranceproof = 1 and insuranceproofprintdate is null)
or (bprintinsurancecert = 1 and insurancecertprintdate is null));

-- Schutzcode auf NNP
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NNP' and cconfidlevel <> 'Protection#0'; -- SVA SG: Protection#5


SELECT count(*) FROM vista.TPVADDRESS adr, vista.TPVADDRESSBASIC adba 
WHERE adba.kpvadbaid=adr.kpvadbaid
AND adba.validfrom > adr.validfrom
AND adr.validto=‘9999-12-31’
AND adr.caddresstype in(‘AddressTyp#WS’, ‘AddressTyp#GS’);

with X as (
    select adr.kpvadrsid, adr.tpvadrsid, adr.validfrom as adr_validfrom, adr.validto as adr_validto,
    ab.kpvadbaid, ab.tpvadbaid, ab.validfrom as ab_validfrom, ab.validto as ab_validto
    from vista.tpvaddress adr
    left join vista.tpvaddressbasic ab on (ab.kpvadbaid = adr.kpvadbaid)
    where adr.validfrom = (
        select min(adr2.validfrom) from vista.tpvaddress adr2 where adr2.kpvadrsid = adr.kpvadrsid
    )
    and ab.validfrom = (
        select min(ab2.validfrom) from vista.tpvaddressbasic ab2 where ab2.kpvadbaid = ab.kpvadbaid
    )
)
select count(distinct x.kpvadrsid) from x where adr_validfrom < ab_validfrom;


select * from vista.tpvpartner where kpvpartid in (
    select count (distinct x.kpvpartid) from (
        select p.kpvpartid, p.tpvpartid, p.personid, p.birthdate, p.validfrom as p_minvalidfrom, p.validto as p_validto
        from vista.tpvpartner p
        where p.cpartnertype = 'PartnerTyp#NP'
        and p.validfrom = (
            select min(validfrom) from vista.tpvpartner p3 where p3.kpvpartid = p.kpvpartid
        )
        and p.birthdate < (
            select min(validfrom) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid
        )
    ) as x -- 44974
) order by kpvpartid;


-- UPI-Mumie Workload
with x as (
    select distinct upi.turupiregisterid, upi.old_ahv_or_nnss, upi.new_nnss, upi.statuscd, upi.actualitycd, upi.delivery_date, upi.lastupdated as upi_lastupdated,
    p.kpvpartid, p.personid, p.lastupdated as p_lastupdated, 
    (select count(distinct r.kpvroleid) from vista.tpvrole r where r.kpvpartid = p.kpvpartid and r.croletype = 'Rolle#IK') as cnt_ik,
    (select count(distinct r2.kpvroleid) from vista.tpvrole r2 where r2.kpvpartid = p.kpvpartid and r2.croletype <> 'Rolle#IK' and r2.croletype <> 'Rolle#STA') as cnt_others,
    (select count(distinct a.kpvadrsid) from vista.tpvaddress a where a.kpvpartid = p.kpvpartid) as cnt_a
    from vista.aurupiregister upi
    join vista.tpvpartner p on ( (p.personid = upi.old_ahv_or_nnss or p.personid = upi.new_nnss) and p.validto > current date)
    where delivery_date between '2020-10-06' and '2020-10-07' -- date range
    and
    (  
        statuscd = '2' and actualitycd='0' -- set to inactive
        or
        statuscd = '3' and actualitycd='0' -- set to invalid 
        or
        statuscd in ( '0' ,'1' ) and actualitycd = '1' -- current entries
    )
)
select count(*) from x where not (x.cnt_ik = 1 and x.cnt_others = 0 and x.cnt_a = 0) -- Minipartner (nur IK- und STA-Rolle, keine Adresse) ausschliessen!
--order by x.p_lastupdated desc; 
; -- 01.10.2020: 973; 02.10.2020: 5854, zwischen 03.10. und 07.10.2020: 0!!!

select count(*) from vista.aurupiregister; -- 54'629'621
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-02'; -- 31355
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-03'; -- 0 (SA)
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-04'; -- 0 (SO)
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-05'; -- 0 (MO)
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06'; -- 137321
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06' and delivery_date = '2020-10-06'; -- 0
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-07' and delivery_date = '2020-10-06'; -- 34331
select count(*) from vista.aurupiregister where delivery_date = '2020-10-04'; -- 0 (SO)
select count(*) from vista.aurupiregister where delivery_date = '2020-10-05'; -- 36392
select count(*) from vista.aurupiregister where delivery_date = '2020-10-06'; -- 34331
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06' and delivery_date = '2020-10-05'; -- 0
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06' and delivery_date = '2020-10-04'; -- 0
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06' and delivery_date = '2020-10-03'; -- 0
select count(*) from vista.aurupiregister where date(lastupdated) = '2020-10-06' and delivery_date = '2020-10-02'; -- 137321

select * from vista.tpvdynamicparams where paramname='PVJURCON_START';
/*
TPVDYNPARAMID  PARAMNAME       PARAMVALUET          PARAMVALUES  LASTUPDATED          
-------------  --------------  -------------------  -----------  -------------------  
3487542953     PVJURCON_START  2020-10-07 00:00:00  (null)       2020-10-07 22:15:23  
*/

-- Postfach-GS
select * from vista.tpvaddress 
left join vista.tpvaddressbasic on
where a.caddresstype='AdressTyp#GS' ;


-- 238086 - ZH - Employer-Archive not updated
-- prodZH: B&Z Buchung 01.-12.2019  nicht ersichtliche im IK (L&Z) Abr. Nr. 10.126.198
select * from vista.tikemployerarchive where billnbr='10126198';
/*
TIKEARCID   BILLNBR   BILLNBROLD  CBRANCHCODE  ADR1   ADR2    ADR3        ADR4            KPVCORRADDRESS  UID     CREGISTERCODE          CLEGALFORM    CEADMINCODE   EDV2000BILLNBRIOLDID  EDV2000PARTNERID  EDV2000BILLDUTYOLDID  EDV2000CORRADDRPARTNERID  VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESSREPL  KPVCORRADDRESSREPL  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP    CMEMBERTYPE   LASTUPDATED          
----------  --------  ----------  -----------  -----  ------  ----------  --------------  --------------  ------  ---------------------  ------------  ------------  --------------------  ----------------  --------------------  ------------------------  ----------  ----------  ------------------------------------  ----------  --------------  ----------------------  ------------------  ------------------  -------------  ----------  ------------  -------------------  
5643594889  10126198  (null)      (null)       Boner  (null)  Rosenhof 1  7208 Malans GR  5427573027      (null)  ERFASSTCOD#MGPBNESTUD  RECHTSFORM#B  EADMINCODE#N  (null)                (null)            (null)                (null)                    2019-01-01  2019-12-31  0e6f1425-ac54-472b-840e-c0ed1f2c9423  5292188164  5292188164      (null)                  (null)              5427573027          SONDERFALL#04  3311898098  MEMBERTYP#AK  2020-10-05 07:44:09  
*/
select * from vista.jikemployerarchive where billnbr='10126198';
/*
TIKEARCID   CHANGE_DATE          CHANGE_USER  PROGRAM           OPERATION  
----------  -------------------  -----------  ----------------  ---------  
5643594889  2020-10-05 07:44:09  ZHigsla      IK:BZ.BW-N001-V2  I          
*/
select * from vista.tsfmqinbound where businessprocessid='838dd0f3-8ed0-4b14-ba18-19b6822d7023' or jmsmessageid='918440fc-0604-4e84-a6d9-ff500489f133';
-- kein Problem ersichtlich...
select * from vista.tsfmqinbound where jmstype='BZ.BW-N001' and lastupdated >= '2020-10-02' and inboundmsg like '%<ns2:BillNumber>10126198</ns2:BillNumber>%';
-- Nochmals geschickt am 2020-10-05 07:44:15
select a.* from vista.tpvaddress a where kpvadrsid='5427573027'; -- WS - validfrom: 1998
/*
TPVADRSID   KPVPARTID   KPVPARTID_MUNAUTHOR  KPVADBAID   KPVADRSID   CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          EGID    EWID    
----------  ----------  -------------------  ----------  ----------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  ------  ------  
5427573026  5292188164  3311898098           5427572886  5427573027  AddressTyp#WS  (null)     (null)     AppendixPo#V  1         1              (null)  N       AddressStr#CH  (null)        1998-03-27  9999-12-31  (null)         2020-06-30 16:30:18  (null)  (null)  
*/
select * from vista.jpvaddressbasic ab where kpvadbaid=5427572886;
/*
TPVADBAID   KPVADBAID   STREET    STREETSX  UPPERSTREET  ZIP     CITY       CITYSX  UPPERCITY  CCANTON    CCOUNTRY    ISPOBOX  VALIDFROM   VALIDTO     LASTUPDATED          UNPRECISE  CHANGE_DATE          CHANGE_USER  PROGRAM                                     OPERATION  
----------  ----------  --------  --------  -----------  ------  ---------  ------  ---------  ---------  ----------  -------  ----------  ----------  -------------------  ---------  -------------------  -----------  ------------------------------------------  ---------  
5427572885  5427572886  Rosenhof  R251      ROSENHOF     720800  Malans GR  M452    MALANS GR  Canton#GR  Country#CH  N        2020-06-30  9999-12-31  2020-06-30 16:30:11  0          2020-06-30 16:30:11  ZH2223       PV:PV-Dlg-500 Adressstamm                   I          
5427572885  5427572886  Rosenhof  R251      ROSENHOF     720800  Malans GR  M452    MALANS GR  Canton#GR  Country#CH  N        2020-06-30  9999-12-31  2020-06-30 16:30:11  0          2020-10-05 07:41:24  ZHigsla      PV:PV-Dlg-500 Adressstamm                   U          
5427572885  5427572886  Rosenhof  R251      ROSENHOF     720800  Malans GR  M452    MALANS GR  Canton#GR  Country#CH  N        2020-06-30  9999-12-31  2020-10-05 07:41:24  0          2020-10-05 07:42:54  ZHigsla      PV:PV-Dlg-70801 Dialog Periode Adressstamm  U          
*/

select * from vista.tpvpartner where kpvpartid in (118979311, 17385995, 17386017, 17386113, 17386121, 17386129, 17386137, 17386506, 17386557, 17386588, 17386761, 17386831, 17387043, 17387070, 17387097, 17387160, 17387201, 17387498, 17387540, 17387565);
-- FAK:
select kpvpartid, name, clegaltype, clegalform, compfundnr, compfundbranchnr, ccompfundtype, validfrom, validto, lastupdated  from vista.tpvpartner where kpvpartid in (216220379, 22468721, 856047, 856058, 856333);

-- BI-Removal:
select * from vista.tikemployerarchive where kpvpartner is null;

-- Ticket 238904 - TI - Adresse doppelt?
select * from vista.tpvaddress where kpvadrsid=1028644 ; -- 8 Perioden, alle mit validfrom = 1963-07-18;sselect * from vista.tpvaddress where kpvadrsid=1028644;
select * from vista.jpvaddress where kpvadrsid=1028644 ;
/*
Defect 80298 TI - Finding PV: LZPV054 A54) Gültigkeit des Partners liegt nach der kleinsten Gültigkeit der Zahl- und Korr.-Adressen
*/


-- 239017 - LI - Adressmutation nicht möglich
select a.*, ab.ccountry from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
order by a.lastupdated desc;

select * from vista.ABDPOSTFILEZIP;
select * from vista.ABDPOSTFILESTREET;

-- 238921 - SO Zugriff auf Strassenfile
select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'PVCONST#PVCONST_57'
order by c.shortcode;
/*
CODE_ID             SHORTCODE   CONST_FIELD      VALUE  MEDIUM_DESCRIPT                                                                                                                                                                            
------------------  ----------  ---------------  -----  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
PVCONST#PVCONST_57  PVCONST_57  PV_ADR_POLG_DLG  Y      Y: error / warning dialogs are shown and user must manually select a POLG from search Dialog.   N: if the system can determine a unique POLG it is automatically assigned to the address.  
*/
select * from vista.jiscmcode where code_id like 'PVCONST#PVCONST_57';

select * from vista.ABDPOSTFILESTREET where ZIP6=455602;
select * from vista.ABDPOSTFILESTREET where ZIP4=4556;
select * from vista.tpvpartner where BFSMUNITIPALNR=2514;


-- Steuerregister-Nr.
select * from vista.tpvpartner where taxregnr is not null; -- ZH: viele alte partner AIT101: keine
select * from vista.tpvpartner where name='Fournier'; -- Karin: 167961623
update vista.tpvpartner set taxregnr='00000000192', lastupdated=current timestamp where kpvpartid=167961623;
select count(*) as cnt_tax from vista.tpvtaxdata;

-- BI-Removal -----------------------------------------------------
select * from vista.tbikeymapping2000;
select * from vista.tbikeymapping2000;

-- simple version, only partners
declare global temporary table tikemployerarchive like vista.tikemployerarchive
on commit preserve rows not logged;

insert into session.tikemployerarchive
select * from vista.tikemployerarchive; -- SG: 590886 @ 5 sec; ZH: 1495463 @ 14 sec

--delete from session.tikemployerarchive;

select distinct ea.tikearcid, ea.billnbr, 
ea.kpvpartner, bi.vista_kpv_key as bi_vista_kpv_key,
ea.kpvcorrpartner, bi_corr.vista_kpv_key as bi_corr_vista_kpv_key,
ea.edv2000partnerid, bi.edv2000_zid_key as bi_edv2000_zid_key,
ea.edv2000corraddrpartnerid, bi_corr.edv2000_zid_key as bi_corr_edv2ooo_zid_key,
ea.validfrom, ea.validto, ea.lastupdated as ea_lastupdated
from vista.tikemployerarchive ea
left join vista.tbikeymapping2000 bi on (bi.edv2000_zid_key = ea.edv2000partnerid and bi.vista_table_name='TPVPARTNER')
left join vista.tbikeymapping2000 bi_corr on (bi_corr.edv2000_zid_key = ea.edv2000corraddrpartnerid and bi_corr.vista_table_name='TPVPARTNER')
where 
(ea.kpvpartner is null and ea.edv2000partnerid is not null)
or
(ea.kpvcorrpartner is null and ea.edv2000corraddrpartnerid is not null); -- SG: 1033 @ 5 sec; ZH: 461 @ 1 sec

-- Strenger:
select distinct ea.tikearcid, ea.billnbr, 
ea.kpvpartner, bi.vista_kpv_key as bi_vista_kpv_key,
ea.kpvcorrpartner, bi_corr.vista_kpv_key as bi_corr_vista_kpv_key,
ea.edv2000partnerid, bi.edv2000_zid_key as bi_edv2000_zid_key,
ea.edv2000corraddrpartnerid, bi_corr.edv2000_zid_key as bi_corr_edv2ooo_zid_key,
ea.validfrom, ea.validto, ea.lastupdated as ea_lastupdated
from vista.tikemployerarchive ea
left join vista.tbikeymapping2000 bi on (bi.edv2000_zid_key = ea.edv2000partnerid and bi.vista_table_name='TPVPARTNER')
left join vista.tbikeymapping2000 bi_corr on (bi_corr.edv2000_zid_key = ea.edv2000corraddrpartnerid and bi_corr.vista_table_name='TPVPARTNER')
where 
(ea.kpvpartner is null and ea.edv2000partnerid is not null and bi.vista_kpv_key is not null)
or
(ea.kpvcorrpartner is null and ea.edv2000corraddrpartnerid is not null and bi_corr.vista_kpv_key is not null); -- SG: 0; ZH: 0

select * from session.tikemployerarchive;
select * from session.tikemployerarchive where kpvpartner is null;
select count(*) as cnt_no_kpvpartner from session.tikemployerarchive where kpvpartner is null; -- SG: 55930
select count(*) as cnt_no_kpvpartner from session.tikemployerarchive where kpvpartner is null and edv2000partnerid is null; -- SG: 55930
select * from session.tikemployerarchive where date(lastupdated) >= current date;

select * from vista.tbikeymapping2000 where edv2000_zid_key=166897; -- Einige Keys nicht in BI-Keymapping!
-- BillNbrIOLDID / BillDutyOldID:
select * from vista.tbikeymapping2000 where edv2000_zid_key in (98136, 41591); -- Einige Keys nicht in BI-Keymapping!

-- EDV2000CORRADDRPARTNERID == KPVCORRPARTNER:
-- 387385916202632
select * from vista.tikemployerarchive where EDV2000CORRADDRPARTNERID = 387385916202632;
select * from vista.tbikeymapping2000 where edv2000_zid_key='387385916202632'; --> Partner: kpvpartid = 4448831
-- EDV2000BILLNBRIOLDID == EDV2000BILLDUTYOLDID
-- 1905081200317
select * from vista.tbikeymapping2000 where edv2000_zid_key='1905081200317'; --> empty

-- EDV2000CORRADDRPARTNERID, ohne Eintrag in BI-Keymapping:
select * from vista.tbikeymapping2000 where edv2000_zid_key=166897;
select count(ea.tikearcid) from vista.tikemployerarchive ea
left join vista.tbikeymapping2000 bi_corr on (bi_corr.edv2000_zid_key = ea.edv2000corraddrpartnerid and bi_corr.vista_table_name='TPVPARTNER')
where ea.edv2000corraddrpartnerid is not null and bi_corr.edv2000_zid_key is null; -- SG: 1034; ZH: 464

-- EDV2000PARTNERID ohne Eintrag in BI-Keymapping:
select count(ea.tikearcid) from vista.tikemployerarchive ea
left join vista.tbikeymapping2000 bi on (bi.edv2000_zid_key = ea.edv2000partnerid and bi.vista_table_name='TPVPARTNER')
where ea.edv2000partnerid is not null and bi.edv2000_zid_key is null; -- SG: 0; ZH: 0

-- TIKBWCORRADDRESS-Tabelle mit Referenzen auf EDV2000:
select * from vista.TIKBWCORRADDRESS where EDV2000CORRADDRPARTNERID is not null; -- SG: 0; ZH: 0

merge into session.tikemployerarchive as tgt
using (
    select distinct ea.tikearcid, ea.billnbr, 
    ea.kpvpartner, bi.vista_kpv_key as bi_vista_kpv_key,
    ea.kpvcorrpartner, bi_corr.vista_kpv_key as bi_corr_vista_kpv_key,
    ea.edv2000partnerid, bi.edv2000_zid_key as bi_edv2000_zid_key,
    ea.edv2000corraddrpartnerid, bi_corr.edv2000_zid_key as bi_corr_edv2ooo_zid_key,
    ea.validfrom, ea.validto, ea.lastupdated as ea_lastupdated
    from vista.tikemployerarchive ea
    left join vista.tbikeymapping2000 bi on (bi.edv2000_zid_key = ea.edv2000partnerid and bi.vista_table_name='TPVPARTNER')
    left join vista.tbikeymapping2000 bi_corr on (bi_corr.edv2000_zid_key = ea.edv2000corraddrpartnerid and bi_corr.vista_table_name='TPVPARTNER')
    where 
    (ea.kpvpartner is null and ea.edv2000partnerid is not null and bi.vista_kpv_key is not null)
    or
    (ea.kpvcorrpartner is null and ea.edv2000corraddrpartnerid is not null and bi_corr.vista_kpv_key is not null)
) as src
on src.edv2000partnerid = tgt.edv2000partnerid
when matched then update set 
tgt.kpvpartner = (
    case when (tgt.kpvpartner is null) then src.bi_vista_kpv_key else tgt.kpvpartner end
    ),
tgt.kpvcorrpartner = (
    case when (tgt.kpvcorrpartner is null) then src.bi_corr_vista_kpv_key else tgt.kpvcorrpartner end
    ),
tgt.lastupdated = current timestamp; -- 0 rows

select * from vista.tbikeymapping2000;
select * from vista.tikemployerarchive ea;

select * from vista.tikemployerarchive ea
left join vista.tbikeymapping2000 bi_corr on (bi_corr.edv2000_zid_key = ea.edv2000corraddrpartnerid and bi_corr.vista_table_name='TPVPARTNER')
where ea.edv2000corraddrpartnerid is not null and bi_corr.edv2000_zid_key is null; -- SG: 1034; ZH: 464

select * from vista.tbikeymapping2000 where edv2000_zid_key=2104;
-- AIT101
select * from vista.tikemployerarchive where kpvpartner is null;

--Dope Version
 SELECT
	*
FROM
	DOPE.DOP_BO_H
WHERE
	REC_IDE = 'IG_OS_DOPE_VERSION' ;
	
-- Fusion VAKs
select * from vista.tpvpartner where clegaltype = 'NNPersonTy#AK' and compfundnr='88'; -- 26183811
-- Vergleiche z.B. kpvpartid=25055505: AK 94.0, fusioniert mit 32.0 (einfach ohne Fusionsdatum, da neues Feld)

-- KEP CM-Config:
select * from vista.TISCMCODETYPE where shortcode='KEPCONF'; -- codetypeno = 48030743
select * from vista.TISCMCODE_REL; -- empty
select * from vista.TISCMCODEXCODE;
select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.shortcode like 'KPSP%'
order by c.value;
/*
CODE_ID               SHORTCODE   VALUE      LONG_DESCRIPT  
--------------------  ----------  ---------  -------------  
VATTRVALS#KPSPshow    KPSPshow    D                         
VATTR#KPSPshow        KPSPshow    STRING(1)                 
VATTR#KPSPtriggr      KPSPtriggr  STRING(1)                 
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPshow    KPSPshow    Y                         
VATTRVALS#KPSPtriggr  KPSPtriggr  Y                         
*/

select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='KEPCONF')
order by c.shortcode;

with overview as (
    select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
    left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
    left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
    left join vista.tiscmcode attr on (attr.codeno = x.code1)
    where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='KEPCONF')
    order by c.value
)
select * from overview where overview.attr_shortcode='KPSPtriggr';  
/*
CODE_ID       SHORTCODE   LONG_DESCRIPT  ATTR_SHORTCODE  ATTR_VALUE  
------------  ----------  -------------  --------------  ----------  
KEPCONF#CARE  CARE        Sorgerecht:    KPSPtriggr      Y           
*/

-- KEP SIT-Testing
select * from vista.tpvkeppb;
select pbtype, count(*) as cnt_pb from vista.tpvkeppb group by pbtype;
/*
PBTYPE  CNT_PB  
------  ------  
KPAD    1319    
KPFR    18      
KPGT    1       
KPSP    6       
KPTD    2       
(null)  8       
*/
SELECT * FROM vista.tpvkeppb WHERE kvn='7567782685373';

select count(*) as cnt_municipality from vista.tpvkeppb where kmunicipalityid is not null; -- 1339

SELECT * FROM vista.tpvkeppb WHERE kvn='7569904655011';
select * from vista.tpvkeppb where ktocanton is not null and ktocanton <> 'ZH'; -- 54
select * from vista.tpvkeppb where pbtype='KPGT' and ktocanton = 'ZH'; -- 1, kpvpartid = 2615713348
select * from vista.tpvkeppb where pbtype='KPGT' and ktocanton <> 'ZH'; -- 0

-- 8-stellige VNR:
select * from vista.tpvpartner where length(socialsecnr) = 8;

-- 239582 - LI - Mitarbeiter kann nicht angezogen werden
select * from vista.jpvrole where kpvroleid=1869001; -- empty
select * from vista.tpvemployee where shortname='lihaha'; -- empty
select * from vista.tpvpartner where name='Hasler-Maier' and firstname='Harry' or kpvpartid=1196465; -- neuer Name von 1196465 = Hasler, Harry
select * from vista.tpvrole where kpvpartid in (select kpvpartid from vista.tpvpartner where name='Hasler-Maier' and firstname='Harry');
-- MIT-Rolle: 70186066 (von kpvpartid = 1196465)
-- AIT
select * from vista.tpvrole where kpvroleid=929844238;

-- 238445 - prodGR: BZ core  - LDAP Benutzerdaten werden nicht mit L&Z PV synchronisiert
-- Die LDAP Benutzerdaten im BZ core werden bei den neuen B&Z-Usern grcaco und grzime nicht mit der L&Z PV synchronisiert.
-- Test mit: grlave
select * from vista.tpvemployee where shortname='grlave'; -- empty
select * from vista.tpvpartner where personid='7564824714527'; -- 52887007
select * from vista.tpvpartner where kpvpartid=52887007; -- ok
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' order by lastupdated desc;

--
select * from vista.tpvaddress;

--
SELECT * FROM VISTA.TIKKOAUREQUEST WHERE iscomplete IS NULL;
select * from vista.tpvpartner where COMPFUNDNR =1 and COMPFUNDBRANCHNR =3;

-- 240712 - LI - IBAN Aegypten
select * from vista.tpvpaymentaddr where iban like 'EG%';
select * from vista.tpvbankbasic where clearingnr='0010052';
select * from vista.tpvbankbasic where ccountry like '%EG';

select c.code_id, c.shortcode, d.long_descript, attr.CODETYPENO as attr_codetypeno, attr.codeno as attr_codeno, attr.code_id as attr_codeid, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='IBANDetail') and c.shortcode='EG'
order by c.value;

select * from vista.tiscmcode attr where attr.codeno=63478190 and attr.shortcode='AutoLookup';
select * from vista.tiscmcode attr where attr.codeno=63530336 and attr.shortcode='BCNoLength';
select * from vista.tiscmcode attr where attr.codeno=63582482 and attr.shortcode='Length';

update vista.tiscmcode attr set attr.value='Y', attr.uuser='TA240712', attr.utst=current timestamp where attr.codeno=63478190 and attr.shortcode='AutoLookup';
update vista.tiscmcode attr set attr.value='8', attr.uuser='TA240712', attr.utst=current timestamp where attr.codeno=63530336 and attr.shortcode='BCNoLength';
update vista.tiscmcode attr set attr.value='29', attr.uuser='TA240712', attr.utst=current timestamp where attr.codeno=63582482 and attr.shortcode='Length';

-- SVA-ZH: Kontact-Center
select count(*) from vista.tpvkepaddress; -- 3410
select * from vista.tpvkepaddress where housenumber like '%/%'; -- 0
select * from vista.tpvkepaddress where housenumber like '%-%'; -- 0

-- Gemeindefusion eduGR:
select n.* from vista.tpvaddress n 
left join vista.tpvaddress o on (o.kpvadrsid = n.kpvadrsid and o.validto = '2020-12-31')
where n.lastupdated >= '2020-12-03' 
and n.validto = '9999-12-31' 
and n.kpvpartid_munauthor = 959939
and o.kpvpartid_munauthor in (960532, 960123, 959565, 959375); -- 851
-- Taxdata:
select n.* from vista.tpvtaxdata n 
left join vista.tpvtaxdata o on (o.kpvtaxdid = n.kpvtaxdid and o.validto = '2020-12-31')
where n.lastupdated >= '2020-12-03' 
and n.validto = '9999-12-31' 
and n.kpvpartid_taxdomicile = 959939
and o.kpvpartid_taxdomicile in (960532, 960123, 959565, 959375); -- 313

-- ALT:
update session.tmp_tpvaddress set kpvpartid_munauthor = 959939, validfrom = '2021-01-01', validto = '9999-12-31',  lastupdated = current timestamp;

-- NEU:
-- 1006550774
update session.tmp_tpvaddress set kpvpartid_munauthor = 1006550774, validfrom = '2021-01-01', validto = '9999-12-31', lastupdated = current timestamp;

--> DKA:
update vista.tpvaddress set kpvpartid_munauthor = 1006550774, lastupdated = current timestamp 
where tpvadrsid in (
    select n.tpvadrsid from vista.tpvaddress n 
    left join vista.tpvaddress o on (o.kpvadrsid = n.kpvadrsid and o.validto = '2020-12-31')
    where n.lastupdated >= '2020-12-03' 
    and n.validto = '9999-12-31' 
    and n.kpvpartid_munauthor = 959939
    and o.kpvpartid_munauthor in (960532, 960123, 959565, 959375)
); -- 851

update vista.tpvtaxdata set kpvpartid_taxdomicile = 1006550774, lastupdated = current timestamp 
where tpvtaxdid in (
    select n.tpvtaxdid from vista.tpvtaxdata n 
    left join vista.tpvtaxdata o on (o.kpvtaxdid = n.kpvtaxdid and o.validto = '2020-12-31')
    where n.lastupdated >= '2020-12-03' 
    and n.validto = '9999-12-31' 
    and n.kpvpartid_taxdomicile = 959939
    and o.kpvpartid_taxdomicile in (960532, 960123, 959565, 959375)
); -- 313


select count(*) from vista.tpvaddress where kpvpartid_munauthor = 959939 and validto = '9999-12-31' and date(lastupdated) = '2020-12-03';


select kpvpartid, tpvpartid, name, clegaltype, ccanton, munauthornr, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where clegaltype='NNPersonTy#POLG' and lastupdated > '2020-12-10' and validto > current date;
/*
KPVPARTID  TPVPARTID  NAME                        CLEGALTYPE       CCANTON    MUNAUTHORNR  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  --------------------------  ---------------  ---------  -----------  --------------  ----------  ----------  -------------------  
70289      21007375   Comune di Serravalle        NNPersonTy#POLG  Canton#TI  151          5050            2012-04-01  9999-12-31  2020-12-11 16:15:19  
70112      140911628  Comune di Avegno Gordevio   NNPersonTy#POLG  Canton#TI  117          5324            2008-05-01  9999-12-31  2020-12-10 12:03:53  
643473677  643473678  Gemeinde Trüllikon          NNPersonTy#POLG  Canton#ZH  (null)       140             1900-01-01  9999-12-31  2020-12-10 19:20:40  
69793      656635116  *Comune di Brione Verzasca  NNPersonTy#POLG  Canton#TI  (null)       5095            2020-10-18  9999-12-31  2020-12-11 13:02:39  
656635322  656635321  Comune di Verzasca          NNPersonTy#POLG  Canton#TI  40           5399            1900-01-01  9999-12-31  2020-12-10 18:53:39  
(...)
*/
--> Verzasca: 656635322
select * from vista.TPVREGIONMUNAUTH where kpvpartid=656635322;
/*
TPVREGMUNAUTHID  KPVREGMUNAUTHID  KPVPARTID  KPVREGIONID  VALIDFROM   VALIDTO     LASTUPDATED          
---------------  ---------------  ---------  -----------  ----------  ----------  -------------------  
670038869        670038870        656635322  8707660      2020-10-18  9999-12-31  2020-12-14 10:24:55  
*/

-- 243799 - ZH - Unexpected: Mandatory WorkItem Type not set by app
select * from vista.TPVKEPPROCESSING;
/*
TPVKEPPROCID  MESSAGEID                             SENDERID  MESSAGETYPE  MESSAGEDATE          EVENTDATE            ACTION  TESTDELIVERYFLAG  STATUS  ERRORMSG  LASTUPDATED          
------------  ------------------------------------  --------  -----------  -------------------  -------------------  ------  ----------------  ------  --------  -------------------  
5945707473    1a21d61b-8966-475a-8340-e1d0436911da  (null)    1118         2020-12-21 05:02:05  2020-12-21 00:00:00  1       0                 P       (null)    2020-12-21 21:33:00  
*/
select * from vista.tpvkeppartner; -- 50
select pbtype, count(*) as cnt_pb from vista.tpvkeppb group by pbtype union select '--TOTAL:', (select count(*) from vista.tpvkeppb) from vista.tpvkeppb;
/*
PBTYPE    CNT_PB  
--------  ------  
(null)    1       
KPFR      4       
KPGT      4       
KPSP      8       
KPAD      11      
--TOTAL:  28      
*/

-- Key: 5945811410
select * from vista.tpvkeppb pb where pb.TPVKEPPBID=5945811410;
/*
TPVKEPPBID  TPVKEPPROCID  TPVKEPPARTID  MESSAGEID                             KPVPARTID  DOCREF            PBTYPE  KVN            VVN            DVN     KOFFICIALNAME  VOFFICIALNAME  DOFFICIALNAME  KFIRSTNAME  VFIRSTNAME  DFIRSTNAME  KDATEOFBIRTH  VDATEOFBIRTH  DDATEOFBIRTH  KSEX  VSEX  DSEX  KDEATHDATE  VDEATHDATE  DDEATHDATE  KMARITALSTATUS  DMARITALSTATUS  VMARITALSTATUS  VDATEOFMARITALSTATUS  KDATEOFMARITALSTATUS  DDATEOFMARITALSTATUS  KCANCELATIONREASON  VCANCELATIONREASON  DCANCELATIONREASON  KSEPARATION  VSEPARATION  DSEPARATION  KSEPARATIONFROM  VSEPARATIONFROM  DSEPARATIONFROM  KSEPARATIONTILL  KNATIONALITYID  VNATIONALITYID  KNATIONALITYISO  VNATIONALITYISO  KNATIONALITYNAME  VNATIONALITYNAME  DNATIONALITY  KNATIONALITYFROM  VNATIONALITYFROM  DNATIONALITYFROM  KRESIDAUTHOR  VRESIDAUTHOR  DRESIDAUTHOR  KRESIDAUTHORSINCE  VRESIDAUTHORSINCE  DRESIDAUTHORSINCE  KRESIDAUTHORTO  VRESIDAUTHORTO  DRESIDAUTHORTO  KENTRYDATE  VENTRYDATE  DENTRYDATE  MR_KVNTARGET  MR_VVNTARGET  MR_DVNTARGET  MR_KFIRSTNAME  MR_KNAME  MR_VFIRSTNAME  MR_VNAME  MR_KTYPEOFREL  MR_VTYPEOFREL  MR_DTYPEOFREL  PR1_KVNTARGET  PR1_VVNTARGET  PR1_DVNTARGET  PR1_KFIRSTNAME  PR1_KNAME    PR1_VFIRSTNAME  PR1_VNAME    PR1_KTYPEOFREL  PR1_VTYPEOFREL  PR1_DTYPEOFREL  PR1_KCARE  PR1_KVALIDFROM  PR1_VVALIDFROM  PR1_DVALIDFROM  PR2_KFIRSTNAME  PR2_KNAME    PR2_VFIRSTNAME  PR2_VNAME    PR2_KVNTARGET  PR2_VVNTARGET  PR2_DVNTARGET  PR2_KTYPEOFREL  PR2_VTYPEOFREL  PR2_DTYPEOFREL  PR2_KCARE  PR2_KVALIDFROM  PR2_VVALIDFROM  PR2_DVALIDFROM  GR_KTYPEOFREL  GR_VTYPEOFREL  GR_DTYPEOFREL  GR_KFIRSTNAME  GR_KNAME  GR_VFIRSTNAME  GR_VNAME  GR_KCARE  GR_KVALIDFROM  GR_VVALIDFROM  GR_DVALIDFROM  KRESIDENCETYPE  VRESIDENCETYPE  DRESIDENCETYPE  KMUNICIPALITYID  KMUNICIPALITYNAME  KARRIVALDATE  VARRIVALDATE  DARRIVALDATE  KFROMCOUNTRYID  KFROMCOUNTRYISO  KFROMCOUNTRYNAME  KFROMCANTON  KFROMMUNICIPALITYID  KFROMMUNICIPALITYNAME  KDEPARTUREDATE  VDEPARTUREDATE  DDEPARTUREDATE  KTOCOUNTRYID  KTOCOUNTRYISO  KTOCOUNTRYNAME  KTOCANTON  KTOMUNICIPALITYID  KTOMUNICIPALITYNAME  KMOVINGDATE  VMOVINGDATE  DMOVINGDATE  KSTREET            VSTREET            DSTREET  KHOUSENUMBER  VHOUSENUMBER  DHOUSENUMBER  KTOWN       VTOWN       DTOWN  KZIP  VZIP  DZIP  KCOUNTRY  VCOUNTRY  DCOUNTRY  KEGID    VEGID    DEGID  KEWID  VEWID  DEWID  KTYPEOFHOUSEHOLD  STATUS  ERRORMSG  LASTUPDATED          
----------  ------------  ------------  ------------------------------------  ---------  ----------------  ------  -------------  -------------  ------  -------------  -------------  -------------  ----------  ----------  ----------  ------------  ------------  ------------  ----  ----  ----  ----------  ----------  ----------  --------------  --------------  --------------  --------------------  --------------------  --------------------  ------------------  ------------------  ------------------  -----------  -----------  -----------  ---------------  ---------------  ---------------  ---------------  --------------  --------------  ---------------  ---------------  ----------------  ----------------  ------------  ----------------  ----------------  ----------------  ------------  ------------  ------------  -----------------  -----------------  -----------------  --------------  --------------  --------------  ----------  ----------  ----------  ------------  ------------  ------------  -------------  --------  -------------  --------  -------------  -------------  -------------  -------------  -------------  -------------  --------------  -----------  --------------  -----------  --------------  --------------  --------------  ---------  --------------  --------------  --------------  --------------  -----------  --------------  -----------  -------------  -------------  -------------  --------------  --------------  --------------  ---------  --------------  --------------  --------------  -------------  -------------  -------------  -------------  --------  -------------  --------  --------  -------------  -------------  -------------  --------------  --------------  --------------  ---------------  -----------------  ------------  ------------  ------------  --------------  ---------------  ----------------  -----------  -------------------  ---------------------  --------------  --------------  --------------  ------------  -------------  --------------  ---------  -----------------  -------------------  -----------  -----------  -----------  -----------------  -----------------  -------  ------------  ------------  ------------  ----------  ----------  -----  ----  ----  ----  --------  --------  --------  -------  -------  -----  -----  -----  -----  ----------------  ------  --------  -------------------  
5945811410  5945707473    5945720605    1a21d61b-8966-475a-8340-e1d0436911da  9277079    2035605945962886  KPSP    7560762776795  7560762776795  (null)  Hopfgartner    Hopfgartner    0              Andrin      Andrin      0           2002-12-19    2002-12-19    0             1     M     0     (null)      (null)      (null)      1               0               L               2002-12-19            (null)                (null)                (null)              (null)              (null)              (null)       (null)       (null)       (null)           (null)           (null)           (null)           (null)          (null)          CH               CH               Schweiz           (null)            0             2002-12-19        2002-12-19        0                 (null)        (null)        (null)        (null)             (null)             (null)             (null)          (null)          (null)          (null)      2002-12-19  (null)      (null)        (null)        (null)        (null)         (null)    (null)         (null)    (null)         (null)         (null)         7563757483128  7563757483128  0              Thalia          Hopfgartner  Thalia          Hopfgartner  3               LK              0               0          (null)          2002-12-19      (null)          John            Hopfgartner  John            Hopfgartner  7565523009181  7565523009181  0              4               LK              0               0          (null)          2002-12-19      (null)          (null)         (null)         (null)         (null)         (null)    (null)         (null)    (null)    (null)         (null)         (null)         0               WS              0               230              Winterthur         2002-12-19    2020-05-30    (null)        (null)          (null)           (null)            (null)       (null)               (null)                 (null)          2020-05-30      (null)          (null)        (null)         (null)          (null)     (null)             (null)               (null)       9999-12-31   (null)       Am Schützenweiher  Am Schützenweiher  0        16            16            0             Winterthur  Winterthur  0      8400  8400  0     CH        CH        0         1159039  1159039  0      1      1      0      1                 P       (null)    2020-12-21 21:32:59  
*/

-- PV-Search: View:
select * from vista.vpvpart_addr; -- partner, address, addressbasic
select * from vista.vpvpart_addr where street='Tobelgasse' and streetnr like '1%'; -- 1: 45; 2: 3
select count(*) as cnt_total from vista.vpvpart_addr where street='Tobelgasse' and streetnr='1'; --45
select count(distinct pkpvpartid) as cnt_kpvpartid from vista.vpvpart_addr where street='Tobelgasse' and streetnr='1'; -- 25

select * from vista.vpvpart_addr where uppername like 'EHRENBERGER%'; -- 8
select count(distinct pkpvpartid) as cnt_kpvpartid from vista.vpvpart_addr where uppername like 'EHRENBERGER%'; -- 7

select * from vista.vpvpart_addr where uppername like 'EHREN%'; -- 704
select * from vista.vpvpart_addr where uppername like 'EHREN%' and pvalidto > current date; -- 392
select * from vista.vpvpart_addr where uppername like 'EHREN%' and pvalidto > current date and (avalidto is null or avalidto > current date) and (bvalidto is null or bvalidto > current date); -- 283
select count(distinct pkpvpartid) as cnt_kpvpartid from vista.vpvpart_addr where uppername like 'EHREN%' and pvalidto > current date and (avalidto is null or avalidto > current date) and (bvalidto is null or bvalidto > current date); -- 262

select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'PVCONST%' and shortcode='PVCONST_5'
order by c.shortcode; -- 400


select * from vista.tpvpartner where socialsecnr='35477532214'; -- 0
select * from vista.tpvpartner where socialsecnr='35477532'; -- 1

-- Company-Nr:
-- This attribute is used in the Principality of Liechtenstein for the legal person  identification number used in the Principality of Liechtenstein. 
-- In Switzerland this attribute is reserved for future use.
select name, clegaltype, clegalform, companynr, lastupdated from vista.tpvpartner where companynr is not null;

-- Mumie-Workload:
-- UPI-Mumie Workload

with x as (
    select distinct upi.turupiregisterid, upi.old_ahv_or_nnss, upi.new_nnss, upi.statuscd, upi.actualitycd, upi.delivery_date, upi.lastupdated as upi_lastupdated,
    upi.deathdate as upi_death,
    p.kpvpartid, p.personid, p.lastupdated as p_lastupdated, p.DEATHDATE, p.VALIDTO,
    (select count(distinct r.kpvroleid) from vista.tpvrole r where r.kpvpartid = p.kpvpartid and r.croletype = 'Rolle#IK') as cnt_ik,
    (select count(distinct r2.kpvroleid) from vista.tpvrole r2 where r2.kpvpartid = p.kpvpartid and r2.croletype <> 'Rolle#IK' and r2.croletype <> 'Rolle#STA') as cnt_others,
    (select count(distinct a.kpvadrsid) from vista.tpvaddress a where a.kpvpartid = p.kpvpartid) as cnt_a
    from vista.aurupiregister upi
    join vista.tpvpartner p on ( (p.personid = upi.old_ahv_or_nnss or p.personid = upi.new_nnss) and p.validto > current date)
    where delivery_date between '2021-01-01' and '2021-01-04' -- date range
    and
    ( 
        statuscd = '2' and actualitycd='0' -- set to inactive
        or
        statuscd = '3' and actualitycd='0' -- set to invalid 
        or
        statuscd in ( '0' ,'1' ) and actualitycd = '1' -- current entries
    )
)
select * from x where not (x.cnt_ik = 1 and x.cnt_others = 0 and x.cnt_a = 0) -- 5036
and (x.upi_death is not null and x.deathdate is null) -- 132
;
select * from vista.tpvdynamicparams;
/*
TPVDYNPARAMID  PARAMNAME       PARAMVALUET          PARAMVALUES  LASTUPDATED          
-------------  --------------  -------------------  -----------  -------------------  
3487542953     PVJURCON_START  2021-01-05 00:00:00  (null)       2021-01-05 22:18:17  
*/
select c.code_id, c.shortcode, c.const_field, c.value, d.medium_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
where c.code_id like 'PVCONST%' and c.shortcode in ('PVCONST_60', 'PVCONST_61')
order by c.shortcode;
/*
CODE_ID             SHORTCODE   CONST_FIELD          VALUE  MEDIUM_DESCRIPT                                                                                                                                                     
------------------  ----------  -------------------  -----  ------------------------------------------------------------------------------------------------------------------------------------------------------------------  
PVCONST#PVCONST_60  PVCONST_60  PV_URCON_MAXWORK     10000  Definiert max. work items für PVJURCON als security gate um zu viele Updates / Postkörbe in PV zu vermeiden falls ZAS ein Massenupdate im UPI-Register durchführt.  
PVCONST#PVCONST_61  PVCONST_61  PV_URCON_MAXUPDATES  1000   Steuert Parameter maximumEntries vom ZA Service findUpdatedUPIEntries (Tranchengrösse). Max. 10'000.       
*/

-- 246562 - prodZH: ERROR: PVJKEPI: Same NNSS was provided multiple times in one XML from KEP (Master-Ticket)
select * from vista.tzaxmlsdxrecord where entrydate='2021-01-11' order by lastupdated desc; -- messagetype = 1118
select * from vista.tpvkepprocessing where date(lastupdated)='2021-01-11'; -- 3
select * from vista.tpvkeppartner where date(lastupdated)='2021-01-11' and ismainpartner=1 and errormsg is not null;
/*
TPVKEPPARTID  TPVKEPPROCID  MESSAGEID                             ISMAINPARTNER  VN             OFFICIALNAME  FIRSTNAME        DATEOFBIRTH  BIRTHDATEPREC  SEX  DEATHDATE  MARITALSTATUS  DATEOFMARITALSTATUS  CANCELATIONREASON  SEPARATION  SEPARATIONVALIDFROM  SEPARATIONVALIDTILL  NATIONALITYID  NATIONALITYISO  NATIONALITYNAME  NATIONALITYVALIDFROM  RESIDAUTHOR  RESIDAUTHORSINCE  RESIDAUTHORTO  ENTRYDATE  STATUS  ERRORMSG    LASTUPDATED          
------------  ------------  ------------------------------------  -------------  -------------  ------------  ---------------  -----------  -------------  ---  ---------  -------------  -------------------  -----------------  ----------  -------------------  -------------------  -------------  --------------  ---------------  --------------------  -----------  ----------------  -------------  ---------  ------  ----------  -------------------  
6004541028    6004540158    1aa95bc7-a527-47f4-a6a0-1816306dbe2f  1              7565169553710  Milovanovic   Milijana         1992-12-10   0              2    (null)     1              1992-12-10           (null)             (null)      (null)               (null)               8100           CH              Schweiz          (null)                (null)       (null)            (null)         (null)     E       PV01400020  2021-01-11 21:33:23  
6004540600    6004540163    b2ae547f-933f-4b9c-a907-62d92b8a735d  1              7567408229288  Piatti        Michela Cellina  1993-05-14   0              2    (null)     1              (null)               (null)             (null)      (null)               (null)               8100           CH              Schweiz          1993-05-14            (null)       (null)            (null)         (null)     E       PV01400020  2021-01-11 21:33:22  
*/
select tpvkeppartid, tpvkepprocid, messageid, ismainpartner, vn, officialname, firstname, status, errormsg, lastupdated from vista.tpvkeppartner where vn in (
    select vn from vista.tpvkeppartner where date(lastupdated)='2021-01-11' and ismainpartner=1 and errormsg is not null
) order by vn;
/*
TPVKEPPARTID  TPVKEPPROCID  MESSAGEID                             ISMAINPARTNER  VN             OFFICIALNAME  FIRSTNAME        STATUS  ERRORMSG    LASTUPDATED          
------------  ------------  ------------------------------------  -------------  -------------  ------------  ---------------  ------  ----------  -------------------  
6004540594    6004540158    1aa95bc7-a527-47f4-a6a0-1816306dbe2f  1              7565169553710  Milovanovic   Milijana         P       (null)      2021-01-11 21:33:50  
6004541028    6004540158    1aa95bc7-a527-47f4-a6a0-1816306dbe2f  1              7565169553710  Milovanovic   Milijana         E       PV01400020  2021-01-11 21:33:23  
6004540286    6004540163    b2ae547f-933f-4b9c-a907-62d92b8a735d  1              7567408229288  Piatti        Michela Cellina  P       (null)      2021-01-11 21:33:53  
6004540600    6004540163    b2ae547f-933f-4b9c-a907-62d92b8a735d  1              7567408229288  Piatti        Michela Cellina  E       PV01400020  2021-01-11 21:33:22  
6014478942    6014472575    f916801a-6708-477e-829a-1b3465f3f737  1              7567408229288  Piatti        Michela Cellina  P       (null)      2021-01-12 21:33:44  
*/
select * from vista.tpvkepprocessing where tpvkepprocid in (6004540158, 6004540163);
/*
TPVKEPPROCID  MESSAGEID                             SENDERID  MESSAGETYPE  MESSAGEDATE          EVENTDATE            ACTION  TESTDELIVERYFLAG  STATUS  ERRORMSG  LASTUPDATED          
------------  ------------------------------------  --------  -----------  -------------------  -------------------  ------  ----------------  ------  --------  -------------------  
6004540158    1aa95bc7-a527-47f4-a6a0-1816306dbe2f  (null)    1118         2021-01-09 05:00:05  2021-01-09 00:00:00  1       0                 P       (null)    2021-01-11 21:33:56  
6004540163    b2ae547f-933f-4b9c-a907-62d92b8a735d  (null)    1118         2021-01-10 05:00:05  2021-01-10 00:00:00  1       0                 P       (null)    2021-01-11 21:33:56  
*/
select * from vista.TZAXMLSDXRECORD where entrydate='2021-01-09' order by lastupdated desc; -- messagetype = 1118

-- KEP_ErrorList
select date(proc.messagedate) as messagedate, proc.tpvkepprocid, p1.tpvkeppartid, p1.vn, 
vista.vistasoundex(p1.officialname) as officialname_sx, vista.vistasoundex(p1.firstname) as firstname_sx, p1.dateofbirth, p1.status,
p2.tpvkeppartid as p2_tpvkeppartid, p2.status as p2_status, 
pb.kpvpartid, pb.pbtype, pb.docref, pb.kfrommunicipalityname, pb.kfromcanton, pb.ktomunicipalityname, pb.ktocanton,  pb.kmunicipalityname,
za.tzaxmlsdxrecordid, za.sdxxmlfilename, proc.messageid, za.messagetype, za.entrydate, 
(select count(px.tpvkeppartid) from vista.tpvkeppartner px where px.tpvkepprocid = p1.tpvkepprocid and px.ismainpartner = 1) as cnt_partner
from vista.tpvkeppartner p1
join vista.tpvkepprocessing proc on (proc.tpvkepprocid = p1.tpvkepprocid)
left join vista.tpvkeppartner p2 on (p2.vn = p1.vn and p2.ismainpartner = 1 and p2.status = 'P' and p2.tpvkepprocid = p1.tpvkepprocid)
left join vista.tpvkeppb pb on (pb.tpvkeppartid = p2.tpvkeppartid)
left join vista.tzaxmlsdxrecord za on (za.entrydate = date(proc.messagedate) and za.messagetype in ('1118', '10099') )
where p1.status = 'E' and p1.ismainpartner = 1
and proc.messagedate between '2022-12-22' and '2022-01-31'
order by proc.tpvkepprocid asc, proc.messagedate asc, p1.vn asc;

-- For p1 only:
select date(proc.messagedate) as "Meldedatum", p1.vn as "NNSS", 
p1.officialname as "Nachname", p1.firstname as "Vorname", p1.dateofbirth as "Geb.-dat.", p1.deathdate as "Todesdatum", --p1.status as "Status",
cast (
    case 
    when p1.maritalstatus = 1 then '1: #L'
    when p1.maritalstatus = 2 then '2: #H/G'
    when p1.maritalstatus = 3 then '3: #W'
    when p1.maritalstatus = 4 then '4: #S'
    when p1.maritalstatus = 5 then '5: #L'
    when p1.maritalstatus = 6 then '6: #GPS/GRP'
    when p1.maritalstatus = 7 then '7: #GGP/GTP'
    when p1.maritalstatus = 9 then '9: #U/L'
    end
as varchar(21))
as "Zivilstand", p1.dateofmaritalstatus as "Dat. Ziv.st.-Aenderung", 
a.arrivaldate as "Zuzugsdatum", a.departuredate as "Wegzugsdatum", a.movingdate as "Umzugsdatum",
a.fromcanton as "Zuzugskanton", a.frommunicipalityname as "Zuzugsgemeinde", a.tocanton as "Wegzugskanton", a.tomunicipalityname as "Wegzugsgemeinde",
a.residencetype as "Meldeverh.", (a.street || ' ' || a.housenumber || ', ' || a.swisszipcode || ' ' || a.town) as "KEP-Adresse",
(vab.street || ' ' || va.streetnr || ', ' || left(coalesce(vab.zip, '    '), 4) || ' ' || vab.city) as "PV-Wohnsitz",
(vzab.street || ' ' || vza.streetnr || ', ' || left(coalesce(vzab.zip, '    '), 4) || ' ' || vzab.city) as "PV-Aufenthalt"
from vista.tpvkeppartner p1
join vista.tpvkepprocessing proc on (proc.tpvkepprocid = p1.tpvkepprocid)
left join vista.tpvkepaddress a on (a.tpvkeppartid = p1.tpvkeppartid)
left join vista.tpvpartner vp on (vp.personid = p1.vn and vp.validto > current date)
left join vista.tpvaddress va on (va.kpvpartid = vp.kpvpartid and va.caddresstype = 'AddressTyp#WS' and va.validto > current date)
left join vista.tpvaddressbasic vab on (vab.kpvadbaid = va.kpvadbaid and vab.validto > current date)
left join vista.tpvaddress vza on (vza.kpvpartid = vp.kpvpartid and vza.caddresstype = 'AddressTyp#AA' and vza.validto > current date)
left join vista.tpvaddressbasic vzab on (vzab.kpvadbaid = vza.kpvadbaid and vzab.validto > current date)
where p1.status = 'E' and p1.ismainpartner = 1
and proc.messagedate between '2022-03-30' and '2022-06-30'
order by proc.tpvkepprocid asc, proc.messagedate asc, p1.vn asc;

-- MQ Versionen
select * from vista.tsfmqinbound where jmstype='LZ.PV-RR001'; -- keine in SG/ZH
select version, count(*) as cnt_in from vista.tsfmqinbound where jmstype='LZ.PV-I001' group by version;


select code.shortcode, lang.long_descript from vista.tiscmcode code
left join vista.tiscmcode_descr lang on (lang.codetypeno = code.codetypeno and lang.codeno = code.codeno and language = 4)
where code.shortcode = 'PV00833010';

select c.code_id, c.shortcode, c.value, d.long_descript from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno)
where c.code_id like 'MSGTYPE#PV00833010'


order by c.SHORTCODE;

-- PV.2021.86818 - Update Notify Service LZ.PV-N001 für Kontaktcenter SVA ZH (OPAL)
select * from vista.tikemployerarchive;

-- 1002370453 
select * from vista.tpvpartner where kpvpartid=1002370453;

-- Soundex:
select * from vista.tpvpartner where name='Mueller';
select * from vista.tpvpartner where namesx in (
    select namesx from vista.tpvpartner where name='Mueller'
);

-- 
select * from vista.tpvkeppb;

-- Validity
select STREET,ZIP,CITY,CCANTON,CCOUNTRY,VALIDFROM,VALIDTO from vista.tpvaddressbasic where STREET like '%Impasse de la colline%' and ZIp ='170600';
select SWIFTNR,CLEARINGNR,BANKNAME,ZIP,CITY,VALIDFROM,VALIDTO from vista.TPVbankbasic where SWIFTNR='KBSGCH22XXX';

-- IBAN
select distinct iban from vista.tpvpaymentaddr;

-- Technical partner search analysis Divya, 09.02.2021
select distinct ea.billnbr, ea.adr1, ea.kpvpartner, ea.validfrom, ea.validto from vista.tikemployerarchive ea where ea.billnbr='Q70677';

select distinct ea.billnbr, ea.adr1, ea.kpvpartner, ea.validfrom, ea.validto from vista.tikemployerarchive ea
join vista.tikemployerarchive ea2 on (ea2.kpvpartner = ea.kpvpartner and ea2.tikearcid <> ea.tikearcid)
where length(ea.billnbr) = 6
order by kpvpartner; -- 110783

select distinct ea.billnbr, ea.adr1, ea.kpvpartner, ea.validfrom, ea.validto from vista.tikemployerarchive ea
join vista.tikemployerarchive ea2 on (ea2.billnbr = ea.billnbr and ea2.kpvpartner <> ea.kpvpartner and ea2.tikearcid <> ea.tikearcid)
order by ea.billnbr;
/*
BILLNBR      ADR1                                      KPVPARTNER  VALIDFROM   VALIDTO     
-----------  ----------------------------------------  ----------  ----------  ----------  
10010007212  Sommer Sennerei Gampernei                 10760663    1948-01-01  1952-12-31  
10010007212  Sommer-Sennerei Gampernei                 11113394    1953-01-01  1980-12-31  
10010015716  Käsereigenossenschaft Salez-Sennwald      10541268    1954-01-01  1963-12-31  
10010015716  Käsereigesellschaft Frümsen               10599749    1964-01-01  1980-12-31  
10010016714  Stefan Brugger AG                         10912764    1965-01-01  1973-12-31  
10010016714  Brugger-Traber Irma AG Vermögensverwaltu  10953716    1974-01-01  1980-12-31  
*/
-- AIT101:
/*
BILLNBR  ADR1                      KPVPARTNER        VALIDFROM   VALIDTO     
-------  ------------------------  ----------------  ----------  ----------  
100016   Ausgleichskasse Obwalden  9000010001200742  1948-01-01  9999-12-31  
100016   Lang,Hans                 9000010001200912  1991-01-01  9999-12-31  
533622   Coiffeur Harmonie         9000010001200053  1950-01-01  9999-12-31  
533622   Coiffeur Myriam           9000010001200054  1981-01-01  9999-12-31  
542308   Teleinform AG             9000010001200010  1980-01-01  1995-12-31  
542308   Teleinform AG             9000010001200911  2006-01-01  2007-12-31  
*/


-- w/o Batchsuche or Batchsuche = 0
-- Step 1:
select distinct tik.kpvpartner as kpv_key  from vista.tikemployerarchive tik ,vista.tpvpartner part  where tik.billnbr = '100016'  and part.kpvpartid=tik.kpvpartner 
Fetch first 50 rows only;
-- 9000010001200742, 9000010001200912
-- Step 2:
select pvPartnerAddressDE.* from vista.VPVPART_ADDR as pvPartnerAddressDE  where   (  pvPartnerAddressDE.pkpvpartid IN (9000010001200742, 9000010001200912) and pvPartnerAddressDE.pvalidfrom <= current date
 and pvPartnerAddressDE.pvalidto >= current date) and   pvPartnerAddressDE.pvalidto >= current date and pvPartnerAddressDE.pvalidfrom <= current date  and 
 (  (  pvPartnerAddressDE.avalidto >= current date and pvPartnerAddressDE.avalidfrom <= current date and  pvPartnerAddressDE.bvalidto >= current date
 and pvPartnerAddressDE.bvalidfrom <= current date  )  or pvPartnerAddressDE.c_tpvadrsid = -1  or exists (   select Addr_past.KPVPARTID, max(Addr_past.validto) 
 from vista.TPVADDRESS Addr_past where  Addr_past.KPVPARTID = pvPartnerAddressDE.pkpvpartid and  Addr_past.TPVADRSID = pvPartnerAddressDE.tpvadrsid  
group by Addr_past.KPVPARTID  having max(Addr_past.validto) < current date   )  or exists (   select Addr_future.KPVPARTID, min(Addr_future.validfrom)  
from vista.TPVADDRESS Addr_future where  Addr_future.KPVPARTID = pvPartnerAddressDE.pkpvpartid and  Addr_future.TPVADRSID = pvPartnerAddressDE.tpvadrsid 
 group by Addr_future.KPVPARTID  having min(Addr_future.validfrom) > current date   )  ) 
ORDER BY pvPartnerAddressDE.uppername, pvPartnerAddressDE.upperfirstname, pvPartnerAddressDE.pkpvpartid    Fetch first    300     rows only; -- 2 Rows

-- with Batchsuche = 1:
-- Step 1:
select tik.kpvpartner  from  vista.tikemployerarchive tik,vista.tpvpartner part where part.kpvpartid=tik.kpvpartner and  tik.billnbr = '100016'  
order by  tik.VALIDTO desc, tik.VALIDFROM desc, tik.LASTUPDATED desc
fetch first 1 row only -- should be here!
; -- 9000010001200912
-- Step 2:
select pvPartnerAddressDE.* from vista.VPVPART_ADDR as pvPartnerAddressDE  where   (  pvPartnerAddressDE.pkpvpartid IN (9000010001200912) and pvPartnerAddressDE.pvalidfrom <= current date
 and pvPartnerAddressDE.pvalidto >= current date) and   pvPartnerAddressDE.pvalidto >= current date and pvPartnerAddressDE.pvalidfrom <= current date  and 
 (  (  pvPartnerAddressDE.avalidto >= current date and pvPartnerAddressDE.avalidfrom <= current date and  pvPartnerAddressDE.bvalidto >= current date
 and pvPartnerAddressDE.bvalidfrom <= current date  )  or pvPartnerAddressDE.c_tpvadrsid = -1  or exists (   select Addr_past.KPVPARTID, max(Addr_past.validto) 
 from vista.TPVADDRESS Addr_past where  Addr_past.KPVPARTID = pvPartnerAddressDE.pkpvpartid and  Addr_past.TPVADRSID = pvPartnerAddressDE.tpvadrsid  
group by Addr_past.KPVPARTID  having max(Addr_past.validto) < current date   )  or exists (   select Addr_future.KPVPARTID, min(Addr_future.validfrom)  
from vista.TPVADDRESS Addr_future where  Addr_future.KPVPARTID = pvPartnerAddressDE.pkpvpartid and  Addr_future.TPVADRSID = pvPartnerAddressDE.tpvadrsid 
 group by Addr_future.KPVPARTID  having min(Addr_future.validfrom) > current date   )  ) 
ORDER BY pvPartnerAddressDE.uppername, pvPartnerAddressDE.upperfirstname, pvPartnerAddressDE.pkpvpartid    Fetch first    300     rows only; -- 1 Row!

--select * from vista.tpvpartner where KPVPARTID in (9000010001200912) order by  VALIDTO desc, VALIDFROM desc; -- wrong SQL?

-- 249508 - SO - ASJMAS500D - Error - Zahlungsverbindungen + Mutationsprotokoll ermitteln
select * from vista.tpvpartner where kpvpartid=952239;
select pa.tpvpaddid, pa.kpvpaddid, pa.kpvpartid, pa.cpaytype, pa.account, pa.iban, pa.accountholder, pa.sapnr, pa.validfrom, pa.validto, pa.lastupdated,
jpa.change_date, jpa.operation, jpa.change_user, jpa.program
from vista.tpvpaymentaddr pa
left join vista.jpvpaymentaddr jpa on (jpa.tpvpaddid = pa.tpvpaddid)
where pa.kpvpartid=952239;
/*
TPVPADDID   KPVPADDID   KPVPARTID  CPAYTYPE      ACCOUNT     IBAN                   ACCOUNTHOLDER  SAPNR   VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          OPERATION  CHANGE_USER  PROGRAM                                          
----------  ----------  ---------  ------------  ----------  ---------------------  -------------  ------  ----------  ----------  -------------------  -------------------  ---------  -----------  -----------------------------------------------  
7084051     7084053     952239     TypePaymen#P  40-12050-2  (null)                                1       1996-01-01  2018-01-11  2018-01-12 07:43:53  (null)               (null)     (null)       (null)                                           
7463217     7463218     952239     TypePaymen#B  1133.92     (null)                                2       1996-01-01  2009-10-30  2009-10-31 00:34:59  (null)               (null)     (null)       (null)                                           
7949164     7949168     952239     TypePaymen#P  00-000-0    (null)                                3       1996-01-01  2018-01-11  2018-01-12 07:43:53  (null)               (null)     (null)       (null)                                           
18487361    7463218     952239     TypePaymen#I  (null)      CH9380926000000113392                 2       2009-10-31  9999-12-31  2009-10-31 00:34:59  (null)               (null)     (null)       (null)                                           
618620525   7084053     952239     TypePaymen#I  (null)      CH6409000000400120502                 1       2018-01-12  9999-12-31  2018-01-12 07:43:53  (null)               (null)     (null)       (null)                                           
618620547   7949168     952239     TypePaymen#I  (null)      CH6209000000000000000                 3       2018-01-12  9999-12-31  2018-01-12 07:43:53  (null)               (null)     (null)       (null)                                           
661817207   661817206   952239     TypePaymen#I  (null)      CH6080774000003613392  BW             (null)  1948-01-01  9999-12-31  2018-05-11 17:52:39  (null)               (null)     (null)       (null)                                           
1132730074  1132730075  952239     TypePaymen#I  (null)      CH2280808008206760368  (null)         1       2020-02-03  9999-12-31  2021-02-11 07:28:30  2021-02-09 08:27:24  I          SO8047       PV:PV-Dlg-303 Zahlungsverbindung                 
1132730074  1132730075  952239     TypePaymen#I  (null)      CH2280808008206760368  (null)         1       2020-02-03  9999-12-31  2021-02-11 07:28:30  2021-02-11 07:28:30  U          SO1358       PV:PV-Dlg-703 Dialog Periode Zahlungsverbindung  
1132730074  1132730075  952239     TypePaymen#I  (null)      CH2280808008206760368  (null)         1       2020-02-03  9999-12-31  2021-02-11 07:28:30  2021-02-11 07:28:30  U          SO1358       PV:PV-Dlg-703 Dialog Periode Zahlungsverbindung  
*/

select *
from vista.jpvpaymentaddr jpa
where jpa.kpvpaddid=1132730075;
/*
TPVPADDID   KPVPARTID  KPVPADDID   KPVBANKID  CPAYTYPE      ACCOUNT  IBAN                   CCOUNTRY  ACCOUNTHOLDER  VALIDFROM   VALIDTO     KPVADRSID  SAPNR  CBORDEREAU  EXTACCOUNTKEY  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                          OPERATION  
----------  ---------  ----------  ---------  ------------  -------  ---------------------  --------  -------------  ----------  ----------  ---------  -----  ----------  -------------  -------------------  -------------------  -----------  -----------------------------------------------  ---------  
1132730074  952239     1132730075  4936433    TypePaymen#I  (null)   CH2280808008206760368  (null)                   2021-02-03  9999-12-31  (null)     1      (null)      (null)         2021-02-09 08:27:24  2021-02-09 08:27:24  SO8047       PV:PV-Dlg-303 Zahlungsverbindung                 I          
1132730074  952239     1132730075  4936433    TypePaymen#I  (null)   CH2280808008206760368  (null)                   2021-02-03  9999-12-31  (null)     1      (null)      (null)         2021-02-09 08:27:24  2021-02-11 07:28:30  SO1358       PV:PV-Dlg-703 Dialog Periode Zahlungsverbindung  U          
1132730074  952239     1132730075  4936433    TypePaymen#I  (null)   CH2280808008206760368  (null)                   2020-02-03  9999-12-31  (null)     1      (null)      (null)         2021-02-11 07:28:30  2021-02-11 07:28:30  SO1358       PV:PV-Dlg-703 Dialog Periode Zahlungsverbindung  U          
*/

-- KEP
select * from vista.tpvkeppb where varrivaldate is not null or vdeparturedate is not null and lastupdated > '2020-01-31';
select status, count(*) as cnt_status from vista.tpvkeppb group by status;
/*
STATUS  CNT_STATUS  
------  ----------  
N       7765        
P       17176       
*/
select * from vista.tpvkeppb where status='N';
select * from vista.tpvkeppartner where tpvkeppartid in (select tpvkeppartid from vista.tpvkeppb where status='N' and pbtype is null);
update vista.tpvkeppb set status='P', lastupdated=current timestamp where status='N' and pbtype is null; 


-- IK - SEDEX
select * from vista.TZAXMLSDXRECORD where entrydate>'2021-01-09' and messagetype='2500' order by lastupdated desc; -- empty
select * from vista.TZAXMLSDXRECORD where entrydate>'2021-01-09' and messagetype not in ('2469', '1118') order by lastupdated desc; -- empty

select * from vista.tpvalias;


-- 251358 - FR - EL - Gemeindefusionen
-- die Gemeinden Arconciel FR, Ependes FR und Senèdes FR seit dem 01.01.2021 zur Gemeinde Bois-d'Amont FR fusioniert sind.
select tpvpartid, kpvpartid, name, clegaltype, bfsmunitipalnr, validfrom, validto, lastupdated from vista.tpvpartner where name like '%Arconciel%'; -- 958097
select tpvpartid, kpvpartid, name, clegaltype, bfsmunitipalnr, validfrom, validto, lastupdated from vista.tpvpartner where name like '%Ependes%'; -- 960975
select tpvpartid, kpvpartid, name, clegaltype, bfsmunitipalnr, validfrom, validto, lastupdated from vista.tpvpartner where name like '%Senèdes%'; -- 959966
select tpvpartid, kpvpartid, name, clegaltype, bfsmunitipalnr, validfrom, validto, lastupdated from vista.tpvpartner where name like '%Bois-d%Amont%'; -- 1102759759
select tpvpartid, kpvpartid, name, clegaltype, bfsmunitipalnr, validfrom, validto, lastupdated from vista.tpvpartner where kpvpartid in (958097, 960975, 959966, 1102759759);
/*
TPVPARTID   KPVPARTID   NAME                     CLEGALTYPE       BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  -----------------------  ---------------  --------------  ----------  ----------  -------------------  
958095      958097      Commune d'Arconciel      NNPersonTy#POLG  2171            1900-01-01  9999-12-31  2019-09-11 07:42:59  
960974      960975      Commune d'Ependes (FR)   NNPersonTy#POLG  2189            1900-01-01  9999-12-31  2019-09-11 07:42:59  
959965      959966      Commune de Senèdes       NNPersonTy#POLG  2225            1900-01-01  9999-12-31  2019-09-11 07:42:59  
1102759758  1102759759  Commune de Bois-d'Amont  NNPersonTy#POLG  2238            1900-01-01  9999-12-31  2020-10-27 08:56:56 
*/
-->
/*
Die Fusion dieser Gemeinden (und den dazugehörigen AHV-Zweigstellen) wurde gemäss DB-Auswertung nicht prozessiert.
Üblicherweise werden dabei die alten Gemeinden "gesternelt" (mutiert, Name enthält ein * am Anfang), damit sie nicht weiter verwendet werden.
Dann erfolgt ein Auftrag an IGS (RfS) um die Fusion durchzuführen. Dazu gibt es einen Prozess und eine Anleitung.
Im Rahmen dieser Beauftragung wird ein Script erstellt, welches alle Adressen mutiert und dabei die neue Gemeinde verknüpft.
Somit sollte dieses Ticket eigentlich als RfS an das IGS Produktmanagement PV.
Hinweis: die vollständige Abarbeitung inkl. Testlauf auf EDU wird mehrere Arbeitstage in Anspruch nehmen. 
*/


-- 252073 - prodTI: Sedex Meldungen im Zentraldruck
select * from vista.tzasedexattachment;
select * from vista.tzaxmlsdxrecord where messagetype=2050;
select * from vista.tzaxmlsdxrecord where tzaxmlsdxrecordid in (
    select tzaxmlsdxrecordid from vista.tzasedexattachment
);

select (replace(replace(recorddata, '<ns2:product>Vista L&amp;Z</ns2:product>', '<ns2:product>Vista LZ</ns2:product>'), '<documentFormat>pdf</documentFormat>', '<documentFormat>application/pdf</documentFormat>')) as recorddata_rep 
from vista.tzaxmlsdxrecord where tzaxmlsdxrecordid in (
    select tzaxmlsdxrecordid from vista.tzasedexattachment
);

update vista.tzaxmlsdxrecord
set recorddata = (replace(replace(recorddata, '<ns2:product>Vista L&amp;Z</ns2:product>', '<ns2:product>Vista LZ</ns2:product>'), '<documentFormat>pdf</documentFormat>', '<documentFormat>application/pdf</documentFormat>')),
state = 3, lastupdated = current timestamp
where tzaxmlsdxrecordid in (
    select tzaxmlsdxrecordid from vista.tzasedexattachment
) and messagetype = 2050 and entrydate >= '2021-03-17';

-- IKJB10104 Logfile (shortened):
/*
2021-03-18 20:40:36,000 INFO  [PID=19889] BJC.sh - BCUX000100 VISTA UNIX batch job started on server [uvigrz0028]
2021-03-18 20:40:36,000 INFO  [PID=19889] BJC.sh - BCUX000114 command line options [-b IKJB10104 -k TI -r 92469440 -s 0 -t 18.03.2021]
2021-03-18 20:40:40,736 INFO  [msrv] BCL              BC20002006 BC Input Parameter, name [WORKER], value [com.ibm.vista.ik.bpc.provider.IkExportKoauDataToSedexBPC] 
    (cmdLine [<null>], cm [com.ibm.vista.ik.bpc.provider.IkExportKoauDataToSedexBPC])
2021-03-18 20:40:41,301 INFO  [msrv] BCL              BC20002005 WorkLoad type WorkItemList, count [1], wis [3013851779/List type WorkItem (IKWITYPE#WILIST)]
2021-03-18 20:40:51,153 INFO  [msrv] BCL              BC20002016   counter [OS DOPiX documents created (OSCOUNTER#OSDOPIXCRE)], ext [IG_IK_KOAU_V], count [1]
2021-03-18 20:40:51,154 INFO  [msrv] BCL              BC20002016   counter [OS DOPiX documents created (OSCOUNTER#OSDOPIXCRE)], ext [IG_IK_KOUB_V], count [1]
2021-03-18 20:40:51,154 INFO  [msrv] BCL              BC20002016   counter [OS DOPiX documents created (OSCOUNTER#OSDOPIXCRE)], ext [IG_IK_SDXB_V], count [1]
2021-03-18 20:40:51,202 INFO  [bjct] BJC              BC20002011 BatchRun ended, returnCode [BR_OK][Ok][0]
*/

select tsfmqoutboundid, status, jmstype, jmscorrelationid, left(jmsdestination, 42) as jmsdestination_short, 
coalesce(substring(outboundmsg, 1485, 19), '') as outbound_doctype, coalesce(substring(outboundmsg, 1847, 27), '') as outbound_docid, lastupdated from vista.tsfmqoutbound
where jmstype in ('DOPIX-RR001', 'DOPIX-N001') and lastupdated >= '2021-03-18 20:40:00' and lastupdated <= '2021-03-18 20:45:00'; -- and outboundmsg like '%"7569515450067"%';
/*
TSFMQOUTBOUNDID  STATUS  JMSTYPE      JMSCORRELATIONID                      JMSDESTINATION_SHORT                        OUTBOUND_DOCTYPE     OUTBOUND_DOCID               LASTUPDATED          
---------------  ------  -----------  ------------------------------------  ------------------------------------------  -------------------  ---------------------------  -------------------  
3016841004       0       DOPIX-RR001  b43ecdc0-5b70-4e5f-8661-b59a8a2154d7  queue:///LZ.DOPIX.RR001.ONLINE.PROCESS.REQ  "IKZ_ZZ_DOT_BRSDXB"  DOCID" v="2107703016840814"  2021-03-18 20:40:41  
3016844000       0       DOPIX-RR001  06b5ff26-2625-450e-8f31-03602248cf05  queue:///LZ.DOPIX.RR001.ONLINE.PROCESS.REQ  "IKZ_ZZ_DOT_BRKOAU"  DOCID" v="2107703016843797"  2021-03-18 20:40:44  
3016847960       0       DOPIX-RR001  24e6ca0b-6fe8-4d44-bb99-3785f7559a15  queue:///LZ.DOPIX.RR001.ONLINE.PROCESS.REQ  "IKZ_ZZ_DOT_BRKOUB"  DOCID" v="2107703016847757"  2021-03-18 20:40:48  
*/

select doctemplname, osdocid, cdoctype, cappstate, creationts, lastupdated from vista.tosdataxml where lastupdated >= '2021-03-18' 
and doctemplname in ('IG_IK_KOUB_V', 'IG_IK_KOAU_V', 'IG_IK_SDXB_V') order by lastupdated desc;
/*
DOCTEMPLNAME  OSDOCID           CDOCTYPE          CAPPSTATE            CREATIONTS           LASTUPDATED          
------------  ----------------  ----------------  -------------------  -------------------  -------------------  
IG_IK_SDXB_V  2107703016840814  OSDOCTYPE#BATCH   OSDOCAPPST#FINISHED  2021-03-18 20:40:41  2021-03-18 20:43:20  
IG_IK_KOUB_V  2107703016847757  OSDOCTYPE#ONLINE  OSDOCAPPST#FINISHED  2021-03-18 20:40:47  2021-03-18 20:43:20  
IG_IK_KOAU_V  2107703016843797  OSDOCTYPE#ONLINE  OSDOCAPPST#FINISHED  2021-03-18 20:40:44  2021-03-18 20:43:19
*/



select * from vista.tosdataxml where lastupdated >= '2021-03-18' 
and doctemplname in ('IG_IK_KOUB_V', 'IG_IK_KOAU_V', 'IG_IK_SDXB_V') order by lastupdated desc;
select tsfmqoutboundid, status, jmstype, jmscorrelationid, left(jmsdestination, 42) as jmsdestination_short, 
outboundmsg, lastupdated from vista.tsfmqoutbound
where jmstype in ('DOPIX-RR001', 'DOPIX-N001') and lastupdated >= '2021-03-18 20:40:00' and lastupdated <= '2021-03-18 20:45:00'; -- and outboundmsg like '%"7569515450067"%';

-- Nach XML-Update:
select tsfmqoutboundid, status, jmstype, jmscorrelationid, left(jmsdestination, 42) as jmsdestination_short, 
coalesce(substring(outboundmsg, 1485, 19), '') as outbound_doctype, coalesce(substring(outboundmsg, 1847, 27), '') as outbound_docid, lastupdated from vista.tsfmqoutbound
where jmstype in ('DOPIX-RR001', 'DOPIX-N001') and lastupdated >= '2021-03-19 20:30:00' and lastupdated <= '2021-03-19 20:45:00'; -- and outboundmsg like '%"7569515450067"%';

-- SDX2050
select c.code_id, c.shortcode, d.long_descript, c.value -- attr.shortcode as attr_shortcode, attr.value as attr_value 
from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
--left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
--left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='SDX2050') --and c.shortcode='EG'
order by c.value;

SELECT * FROM VISTA.AURUPIREGISTER where '7569088651335' in (OLD_AHV_OR_NNSS,NEW_NNSS);
SELECT * FROM VISTA.AURUPIREGISTER where OLD_AHV_OR_NNSS = '7569088651335' or NEW_NNSS = '7569088651335';

-- Alias
select p.kpvpartid, a.aliasterm, p.name, p.cpartnertype from vista.tpvalias a left join vista.tpvpartner p on (p.kpvpartid = a.kpvpartid); -- where p.kpvpartid=957183;


-- 252041 -  ZH -PV-WP-02/searchPartners: Abrechnungsnummer leer an ELAR zurück
/*
18.03.21 15:38:06.59: executeFunction: sequenceID=20294967, functionID=PV-WP-02, vistaDocRef=VDR7715380049399089, indexValues={{R_ABRECHNR=},{TB_BUTTONS=1}}
18.03.21 15:40:15.49: executeFunction: return={{PID=V394552767},{R_NAME=Berthoud},{R_SEX=M},{R_SPRACHE=D},{R_VORNAME=Francois Charles},{R_VERSNR=16161391216},{R_PERSONENID=7566823852125},{R_ABRECHNR=},{R_SCHUTZSTUFE=0},{R_ANREDE=Herr},{R_TITEL=},{R_GEBDAT=19610929},{R_WS_STRASSE=Paulstrasse},{R_GS_STRASSE=Paulstrasse},{R_WS_NUMMER=12},{R_GS_NUMMER=12},{R_WS_PLZ=8008},{R_GS_PLZ=8008},{R_WS_ORT=Zürich},{R_GS_ORT=Zürich},{R_WS_LAND=CH},{R_GS_LAND=CH},{R_UID=},{STATUS=VOLLSTAENDIG}} (sequenceID=20294967, functionID=PV-WP-02, vistaDocRef=VDR7715380049399089, indexValues={{R_ABRECHNR=},{TB_BUTTONS=1}})
==> return: {R_ABRECHNR=}
*/
select * from vista.tpvpartner where personid='7566823852125'; -- 394552767
select * from vista.tikemployerarchive where kpvpartner=394552767;
/*
TIKEARCID   BILLNBR  ADR1      VALIDFROM   VALIDTO     KPVPARTNER  LASTUPDATED          
----------  -------  --------  ----------  ----------  ----------  -------------------  
2540294183  WS5463   Berthoud  2007-06-01  2016-12-31  394552767   2021-03-08 17:47:28  
1224463038  EE2004   Berthoud  2007-06-01  2016-12-31  394552767   2021-01-20 12:20:49   
*/

--  
SELECT * FROM vista.TSFMQINBOUND WHERE JMSTYPE ='LZ.PV-I003' AND JMSMESSAGEID LIKE '%414d5120545353325a4850202020202034c7576022e0ff99%';
-- 5833498324
select * from vista.jpvpartner where kpvpartid=5833498324;
-- CLP Asylanten_anlegen_V_02.sql
-- 83741334-20201123-152502 - RFS 240212
select * from vista.tpvrole where kpvpartid=5833498324; -- kpvroleid = 5833498328 (nur VB, ohne STA-Rolle)
select * from vista.tsfmqevent where key1 = 5833498324 or key2=5833498324; -- empty
select * from vista.tsfmqevent where key1 = 5833498328 or key2=5833498328; -- empty

select outb.REASON, count, date(outb.LASTUPDATED)
from vista.TSFMQOUTBOUND outb
where outb.REASON is not NULL AND jmstype= 'LZ.PV-I003'
and outb.LASTUPDATED >= current timestamp - 1 DAY
group by date(outb.LASTUPDATED), outb.REASON;
/*
REASON               2       3           
-------------------  ------  ----------  
MQOUTBREJ#BEANERROR  411     2021-03-23  
MQOUTINFO#REPNOTREQ  49863   2021-03-23  
MQOUTBREJ#BEANERROR  520422  2021-03-24  
*/
select r1.* from vista.tpvrole r1 
left join vista.tpvrole r2 on (r2.kpvpartid = r1.kpvpartid and r2.kpvroleid <> r1.kpvroleid and r2.croletype='Rolle#STA')
where r1.croletype='Rolle#VB' and r2.kpvroleid is null; -- 295

select * from vista.tpvpartner;

-- PVJREPLI / ASJMAS500
select distinct r1.* from vista.tpvpartnerreplication r1
join vista.tpvpartnerreplication r2 on (r2.kpvpartid = r1.kpvpartid and r2.ctargetappl = r1.ctargetappl and r2.tpvpartrepid <> r1.tpvpartrepid)
where r1.ctargetappl='BusinessAp#AS';

-- NBRAK
select nbrak, count(*) as cnt_nbrak 
from migration.tdmikzikexecution
group by nbrak
order by 2 desc;

-- KEP - unnötige Postkörbe
select * from vista.tpvkeppb where kdeparturedate is not null and (kmovingdate is null or kdeparturedate > kmovingdate) and ktocanton='ZH' and pbtype='KPAD' order by lastupdated desc;
select count(*) from vista.tpvkeppb where kdeparturedate is not null and (kmovingdate is null or kdeparturedate > kmovingdate) and ktocanton='ZH' and pbtype='KPAD'; -- 4877
select count(*) from vista.tpvkeppb where kdeparturedate is not null and (kmovingdate >= kdeparturedate) and ktocanton='ZH' and pbtype='KPAD'; -- 0
select count(*) from vista.tpvkeppb where kdeparturedate is not null and kdeparturedate > kmovingdate and ktocanton='ZH' and pbtype='KPAD'; -- 657
select count(*) from vista.tpvkeppb where kdeparturedate is not null 
and (kmovingdate is null or kdeparturedate > kmovingdate) and (karrivaldate is null or kdeparturedate > kmovingdate) and ktocanton='ZH' and pbtype='KPAD'; -- 657
select count(*) from vista.tpvkeppb where kdeparturedate is not null and kdeparturedate > kmovingdate and kdeparturedate > karrivaldate and ktocanton='ZH' and pbtype='KPAD'; -- 657
select * from vista.tpvkeppb where kdeparturedate is not null and ktocanton<>'ZH' and pbtype='KPGT';


-- 39381: Dummy-Splitting 20:  7565759052050
select * from vista.tikheader where vnr='7565759052050'; -- 76554013
select * from vista.tikowner where tikownrid=76554013; -- role = 70486432
select * from vista.tikzikexecution where vnr = '7565759052050';

-- 39442: Dummy-Splitting 12: 7567790915103
select * from vista.tikheader where vnr='7567790915103'; -- 77829913
select * from vista.tikowner where tikownrid=77829913; -- role = 75100959


-- 253643 - IK - Ungenaues Geb.-Dat.
select * from vista.tikheader where vnr='7565446252794';
/*
TIKHEADID  TIKOWNRID  VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
449142081  77470974   7565446252794  MUELLER,MALEE  1953       0           0         SEXCODEZAS#2  BSVLAND#100  7560190899332  F                2016-11-08 20:34:03  
*/
select * from vista.aurupiregister where new_nnss='7565446252794' and actualitycd=1;
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME           GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  -------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1304441715        7565446252794    7565446252794  0         1            MUELLER,MALEE  2         00001953  100            950000    (null)     2              (null)             15101999           (null)         2021-04-08 11:59:19  
*/
SELECT * FROM vista.TIKKOAUREQUEST WHERE REQUESTID = 3014612557 ;
/*
REQUESTID   MESSAGEID                             SENDERID  ISCOMPLETE  ZIKREQUESTID  TIKZIORID   ERRORCODE  ERRORMESSAGE  MESSAGEXML  LASTUPDATED          
----------  ------------------------------------  --------  ----------  ------------  ----------  ---------  ------------  ----------  -------------------  
3014612557  E6691650-86A3-11EB-B6BD-0050569F1C2F  SEDEX     1           3014612553    3019249920  0          (null)        3014607043  2021-04-09 20:44:15  
*/
SELECT * FROM vista.TZAXMLSDXRECORD WHERE TZAXMLSDXRECORDID=3014607043; -- data_5804320802483473524data_d9dfed8f-d9d9-4e8c-ae1c-c4e1bdaa84f2.zip
select * from vista.tzasedexattachment WHERE TZAXMLSDXRECORDID=3014607043;

select r.* from vista.tzaxmlsdxrecord r where r.messagetype='2050' and r.state=6 and not exists (
    select 1 from vista.tzasedexattachment a where a.tzaxmlsdxrecordid = r.tzaxmlsdxrecordid
); -- viele
select r.* from vista.tzaxmlsdxrecord r where r.messagetype='2050' and r.state=6 and exists (
    select 1 from vista.tzasedexattachment a where a.tzaxmlsdxrecordid = r.tzaxmlsdxrecordid
); -- empty
select r.* from vista.tzaxmlsdxrecord r where r.messagetype='2050' and exists (
    select 1 from vista.tzasedexattachment a where a.tzaxmlsdxrecordid = r.tzaxmlsdxrecordid
); -- viele in Status = 4
select * from vista.tzasedexattachment where tzaxmlsdxrecordid=3014631532;
SELECT * FROM vista.TZAXMLSDXRECORD WHERE tzaxmlsdxrecordid in (3019235219, 3077367947);
select * from vista.tzasedexattachment WHERE tzaxmlsdxrecordid in (3019235219, 3077367947);

SELECT * FROM vista.TZAXMLSDXRECORD WHERE recorddata LIKE '%vn>7564486899280</ns%' and lastupdated > '2021-04-09 20:44:15'; -- 3075522327
select * from vista.tzasedexattachment WHERE tzaxmlsdxrecordid in (3075522327);


select * from vista.tikheader where vnr='7564486899280';
/*
TIKHEADID   TIKOWNRID  VNR            NAME            BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ---------  -------------  --------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
2002228218  431308     7564486899280  D'ELIA,MICHELE  1976       0           0         SEXCODEZAS#1  BSVLAND#218  28076303284    F                2021-03-19 20:22:38  
*/
select * from vista.aurupiregister where new_nnss='7564486899280' and actualitycd=1;
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME            GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  --------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1942568898        7564486899280    7564486899280  0         1            D'ELIA,MICHELE  1         00001976  218            950000    (null)     4              (null)             25012017           (null)         2021-04-10 20:15:44  
*/
SELECT * FROM vista.TIKHEADER WHERE TIKHEADID =2002228218;


-- 252698 - IK - ZH - Plus-Icon funktioniert nicht immmer
-- Not working case 1:
select * from vista.tpvrole r where r.kpvroleid in (select kpvroleid from vista.tikowner o where o.tikownrid in (select tikownrid from vista.tikheader h where h.vnr='7560000749642')); -- 377862586
select * from vista.tpvrole r where r.kpvroleid in (select kpvroleid from vista.tikowner o where o.tikownrid in (select tikownrid from vista.tikheader h where h.vnr='7560001234550')); -- 377854969
-- Working case:
select * from vista.tpvrole r where r.kpvroleid in (select kpvroleid from vista.tikowner o where o.tikownrid in (select tikownrid from vista.tikheader h where h.vnr='7560000846068')); -- 377862650 (sehr viele Bookings)
select * from vista.tpvrole r where r.kpvroleid in (select kpvroleid from vista.tikowner o where o.tikownrid in (select tikownrid from vista.tikheader h where h.vnr='7560002042956')); -- 377868851


-- ECM-Search + NNSS
select * from vista.aurupiregister where old_ahv_or_nnss='7564654996162' or new_nnss='7564654996162'; -- empty
select * from vista.aurupiregister where old_ahv_or_nnss='7561635555684' or new_nnss='7561635555684';
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                 
----------------  ---------------  -------------  --------  -----------  -------------------  
100610            43652305114      7561635555684  0         1            HALS_IK,ABSCHNEIDER  
*/

select * from vista.tikemployerarchive where UID is not null; -- 
select * from vista.tikheader;


-- Normaler Versicherter (hier mit IK-Fachrolle) mit Adresse und aktuellem Eintrag im UPI-Register:
select distinct p.kpvpartid, p.personid, p.socialsecnr, a.kpvadrsid, upi.old_ahv_or_nnss, upi.new_nnss, upi.statuscd, upi.actualitycd, h.tikheadid, h.vnr, ea.billnbr, ea.cregistercode, ea.cmembertype
from vista.tpvpartner p
left join vista.aurupiregister upi on (upi.old_ahv_or_nnss=p.personid or upi.new_nnss=p.personid)
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
left join vista.tikowner o on (o.kpvroleid = r.kpvroleid)
left join vista.tikheader h on (h.tikownrid = o.tikownrid)
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid)
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
where p.validto > current date and h.tikheadid is not null and a.kpvadrsid is not null and upi.actualitycd=1;
-- KPVPARTIDs:
-- 9000010001050849
-- 9000010001050374
-- 9500000000317212

-- Firmen mit Abr.- Nr.
select distinct p.kpvpartid, p.cpartnertype, p.clegaltype, p.name, p.personid, p.socialsecnr, a.kpvadrsid, ea.billnbr, ea.uid, ea.adr1, ea.cregistercode, ea.cmembertype
from vista.tpvpartner p
left join vista.aurupiregister upi on (upi.old_ahv_or_nnss=p.personid or upi.new_nnss=p.personid)
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
left join vista.tikowner o on (o.kpvroleid = r.kpvroleid)
left join vista.tikheader h on (h.tikownrid = o.tikownrid)
left join vista.tikemployerarchive ea on (ea.kpvpartner = p.kpvpartid and ea.validto > current date)
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid)
where p.validto > current date and a.kpvadrsid is not null and ea.billnbr is not null;
-- KPVPARTIDs:
-- 9000010001200771
-- 9000010001200072
-- 9000010001200706
-- 9000010001200015

-- Selbständig-Erwerbende (Natürliche Personen mit Abr.-Nr.)
-- Auf AIT nicht vorhanden!
-- Muss entweder manuell neu erstellt werden, oder (Hack) über SQL den Partnertyp von NNP auf NP umschiessen.
-- Hinweis: Arbeitgeberdaten (in TIKEMPLOYERARCHIVE) werden in Produktion im B&Z Core (Löwenfels) gepflegt und via MQ in VISTA importiert.
-- SQL für Hack: 
update vista.tpvpartner set cpartnertype='PartnerTyp#NP', csex='Sex#U', lastupdated=current timestamp where kpvpartid in (9000010001200961, 9000010001200992, 9000010001200062);
-- KPVPARTIDs:
-- 9000010001200961
-- 9000010001200992
-- 9000010001200062

-- Suche nach UID:
-- Ebenfalls nicht vorhanden auf AIT (Grund siehe oben). Hack:
select * from vista.tikemployerarchive where kpvpartner=9000010001200935;
update vista.tikemployerarchive set uid='CHE123456789', lastupdated=current timestamp where kpvpartner=9000010001200935;
-- KPVPARTIDs:
-- 9000010001200935


select * from vista.tikemployerarchive;
-- ERfasst-Code = cregistercode
select cregistercode, count(*) as cnt from vista.tikemployerarchive group by cregistercode; -- null
select cmembertype, count(*) as cnt from vista.tikemployerarchive group by cmembertype; -- null only
select uid, count(*) as cnt from vista.tikemployerarchive group by uid; -- null
select ea.*, p.kpvpartid from vista.tikemployerarchive ea
join vista.tpvpartner p on (p.kpvpartid = ea.kpvpartner and p.cpartnertype like '%#NP'); -- null


-- 251693 - ZH - Gemeindefusion - Welschenrohr-Gänsbrunnen
-- Die Gemeinden Welschenrohr und Gänsbrunnen haben per 01.01.2021 fusioniert. Die Gemeinde heisst neu Welschenrohr-Gänsbrunnen.
-- EDU ZH:
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (2429, 2423, 2430) or ahvbranchnr in (-1)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID   KPVPARTID   KPVPARTID_AHVBRANCHNR  NAME                               ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------------------  ---------------------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
3311894947  3311894940  3287894266             Gemeinde Gänsbrunnen               (null)          NNPersonTy#POLG  (null)       (null)       (null)         2423            1900-01-01  2020-12-31  2021-03-15 07:43:03  
6211760430  3311894940  3287894266             *Gemeinde Gänsbrunnen              (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   (null)          2021-01-01  9999-12-31  2021-03-15 07:43:20  
3311895057  3311895052  3287894266             Gemeinde Welschenrohr              (null)          NNPersonTy#POLG  (null)       (null)       (null)         2429            1900-01-01  2020-12-31  2021-03-15 07:42:10  
6211760423  3311895052  3287894266             *Gemeinde Welschenrohr             (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   (null)          2021-01-01  9999-12-31  2021-03-15 07:42:10  
6211759628  6211759629  3287894266             Gemeinde Welschenrohr-Gänsbrunnen  (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   2430            2021-01-01  9999-12-31  2021-03-15 07:42:23  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.munauthornr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311894940, 3311895052) or 
    t.kpvpartid_taxdomicile in (3311894940, 3311895052) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid; -- 42

-- 254041 - ZH - Gemeindefusion: Noble_Contrée
-- Die Gemeinden Miège, Venthone und Veyras haben per 01.01.2021 fusioniert. Die Gemeinde heisst neu Noble-Contrée.
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (6241, 6249, 6250, 6254) or ahvbranchnr in (-1)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID   KPVPARTID   KPVPARTID_AHVBRANCHNR  NAME                    ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------------------  ----------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
3311891877  3311891874  3287894266             Gemeinde Miège          (null)          NNPersonTy#POLG  (null)       (null)       (null)         6241            1900-01-01  2020-12-31  2021-04-16 06:50:17  
6267377308  3311891874  3287894266             *Gemeinde Miège         (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   (null)          2021-01-01  9999-12-31  2021-04-16 06:50:17  
3311891901  3311891898  3287894266             Gemeinde Venthône       (null)          NNPersonTy#POLG  (null)       (null)       (null)         6249            1900-01-01  2020-12-31  2021-04-16 06:50:44  
6267377330  3311891898  3287894266             *Gemeinde Venthône      (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   (null)          2021-01-01  9999-12-31  2021-04-16 06:50:44  
3311891912  3311891910  3287894266             Gemeinde Veyras         (null)          NNPersonTy#POLG  (null)       (null)       (null)         6250            1900-01-01  2020-12-31  2021-04-16 06:51:03  
6267377334  3311891910  3287894266             *Gemeinde Veyras        (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   (null)          2021-01-01  9999-12-31  2021-04-16 06:51:03  
6267378003  6267378004  3287894266             Gemeinde Noble-Contrée  (null)          NNPersonTy#POLG  (null)       (null)       FLGAllocat#G   6254            2021-01-01  9999-12-31  2021-04-16 06:53:02  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.munauthornr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as ahv_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.munauthornr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as ahv_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311891874, 3311891898, 3311891910) or 
    t.kpvpartid_taxdomicile in (3311891874, 3311891898, 3311891910) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid; -- Edu: 39 / Prod: 


-- Defect 90558: [ifix] IK_OS_Dopix - IG_IK_KOAU_V Textbaustein korrigieren und IG_IK_KOUB_V ELAR-PID korrigieren
select * from vista.tikheader where vnr='7561311188908'; -- 76806518
select * from vista.tikowner where tikownrid=76806518; -- role: 71324451
select * from vista.tzaxmlsdxrecord where messagetype='2050' and lastupdated > '2021-04-27' and recorddata like '%7561311188908%';

-- Anwalt
select kpvpartid, cpartnertype, name, clegaltype, clegalform from vista.tpvpartner where uppername like '%ANWALT%';


-- 254308 - TI - Gemeindefusion_TI_Tresa_EDU_V1.0.docx
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (5178, 5202, 5222, 5213) or ahvbranchnr in (-1, -2)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
/*
TPVPARTID  KPVPARTID  KPVPARTID_AHVBRANCHNR  NAME                   ADDITIONALNAME  CLEGALTYPE       MUNAUTHORNR  AHVBRANCHNR  CMUNAUTHORFLG  BFSMUNITIPALNR  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------------------  ---------------------  --------------  ---------------  -----------  -----------  -------------  --------------  ----------  ----------  -------------------  
69979      69981      8744967                Comune di Croglio      (null)          NNPersonTy#POLG  95           (null)       FLGAllocat#T   5178            1900-01-01  9999-12-31  2021-03-12 10:10:04  
70373      70374      8755610                Comune di Monteggio    (null)          NNPersonTy#POLG  171          (null)       FLGAllocat#T   5202            1900-01-01  9999-12-31  2021-03-12 10:10:04  
70468      70470      8758761                Comune di Ponte Tresa  (null)          NNPersonTy#POLG  200          (null)       FLGAllocat#T   5213            1900-01-01  9999-12-31  2021-03-12 10:10:04  
70725      70726      8761236                Comune di Sessa        (null)          NNPersonTy#POLG  231          (null)       FLGAllocat#T   5222            1900-01-01  9999-12-31  2021-03-12 10:10:04  
*/
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (69981, 70374, 70726) or 
    t.kpvpartid_taxdomicile in (69981, 70374, 70726) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;


-- 250154 - ZH - Doppelt angelegte VA-IK-Anträge aus E-Admin
/*
Hier dürfte die Parallelisierung keinen Einfluss gehabt haben. Wie aus den XMLs hervorgeht, wurden innert 12 Sekunden UNTERSCHIEDLICHE Requests an L&Z geschickt.
messageDates:
2021-01-21T13:24:35.261
2021-01-21T13:24:38.355
2021-01-21T13:24:41.386
2021-01-21T13:24:44.621
2021-01-21T13:24:47.886
Das Message-Bean von L&Z-IK prozessiert Meldung für Meldung. Jede Meldung muss abgeholt werden. Eine Konsolidierung ist nicht vorgesehen und wohl auch schwer realisierbar - welche dieser 5 Meldungen wäre denn jetzt korrekt und warum? Was passiert mit den "Falschen"? Wie könnte garantiert werden, dass die letzte, korrekte Meldung auch als letzte, aber einzige Meldung in L&Z ankommt und erfolgreich weiterprozessiert wird?

Es sollte zunächst viel eher analysiert werden, warum AHVeasy innert kurzer Zeit so viele (ähnliche, aber eben doch unterschiedliche) Meldungen zum gleichen Versicherten schickt.
Vielleicht wäre es eine Möglichkeit, in AHVeasy eine Verzögerung einzubauen und z.B. nur alle 5 Minuten den letzten Request zu einem Versicherten in die Queue zu stellen? Oder in der Applikation ein Fehler kommt, wenn für den gleichen Versicherten bereits in einem definierten Zeitraum ein anderer Request abgesetzt wurde?

-- Andrea:
Der Unterschied ist, dass diese Versicherte unterschiedliche Startdaten haben (Arbeitsverhältnisse), welche in ELM so erfasst wurden, somit soweit korrekt.
Von L&Z würde eigentlich erwartet, dass mit der ersten Verarbeitung einer Message der entsprechende IK-Antrag erstellt wird und der folgende Eintrag 'verworfen' wird, da bereits ein IK-Antrag besteht. Doch leider werden momentan mehrere IK-Anträge für die gleiche Person erstellt, m.E. aufgrund der Parallelisierung.
@SD: Bitte um Klärung durch Gerry Broennimann (IBM), wie es sein kann, dass für einen Versicherten mehrere identische IK-Anträge erstellt werden können, obwohl das System dies 'eigentlich' nicht zulässt. Danke.

*/
select * from vista.jikrequestheader where pendvnr = '7561976268274' and program like 'IK:EA.N001_V2';
/*
TIKRQHEID   TIKVAIKREQID  TIKZIKREQID  TIKSPLITTINGREQID  PENDVNR        PENDNAME  PENDFIRSTNAME   PENDNAMEZAS          PENDBIRTHYEAR  PENDBIRTHMONTH  PENDBIRTHDAY  CPENDSEX      CPENDCOUNTRY  PRIORITY  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM        OPERATION  
----------  ------------  -----------  -----------------  -------------  --------  --------------  -------------------  -------------  --------------  ------------  ------------  ------------  --------  -------------------  -------------------  -----------  -------------  ---------  
6049834480  6049834477    (null)       (null)             7561976268274  GANZ      MICHAEL THOMAS  GANZ,MICHAEL THOMAS  1955           7               4             SEXCODEZAS#1  BSVLAND#100   0         2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834481  6049834478    (null)       (null)             7561976268274  GANZ      MICHAEL THOMAS  GANZ,MICHAEL THOMAS  1955           7               4             SEXCODEZAS#1  BSVLAND#100   0         2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834482  6049834479    (null)       (null)             7561976268274  GANZ      MICHAEL THOMAS  GANZ,MICHAEL THOMAS  1955           7               4             SEXCODEZAS#1  BSVLAND#100   0         2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834487  6049834486    (null)       (null)             7561976268274  GANZ      MICHAEL THOMAS  GANZ,MICHAEL THOMAS  1955           7               4             SEXCODEZAS#1  BSVLAND#100   0         2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
*/
-- Note: already deleted again.
select * from vista.tikheader where vnr='7561976268274'; -- 402159938
select * from vista.tikowner where tikownrid=402159938; -- IK-role: 381527353
select * from vista.tikrequestheader where pendvnr = '7561976268274'; -- deleted by IK:IKJVADB302:6265504439 - 2021-03-12 22:34:04 or IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e
select * from vista.tikvaikrequest where tikvaikreqid in (select tikvaikreqid from vista.jikrequestheader where pendvnr = '7561976268274' and program like 'IK:EA.N001_V2'); -- deleted
select * from vista.jikvaikrequest where tikvaikreqid in (select tikvaikreqid from vista.jikrequestheader where pendvnr = '7561976268274' and program like 'IK:EA.N001_V2') and operation='I';
/*
TIKVAIKREQID  KPVROLEID  TIKVIOOID   DELIVERYADDRESSIK  DELIVERYADDRESSPK  CSZ       CSZIKOPEN  AKNOTICE           REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CPENDPROTECTIONCODE  BHASALREADYIK  BILLNO  ENTRYDATE   INSURANCEPROOFPRINTDATE  INSURANCECERTPRINTDATE  BPRINTINSURANCEPROOF  BPRINTINSURANCECERT  PRINTINGLANGUAGE  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM        OPERATION  
------------  ---------  ----------  -----------------  -----------------  --------  ---------  -----------------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -------------------  -------------  ------  ----------  -----------------------  ----------------------  --------------------  -------------------  ----------------  -------------------  -------------------  -----------  -------------  ---------  
6049834477    381527353  6049815982  (null)             37287763           SZMZR#67  (null)     F55.192 / E-ADMIN  2021-01-21   33269   (null)            (null)          MZRFEHLER#-1     0                     MDB        Protection#0         (null)         F55192  2020-10-01  (null)                   (null)                  0                     (null)               CorresLang#D      2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834478    381527353  6049815982  (null)             37287763           SZMZR#67  (null)     F55.192 / E-ADMIN  2021-01-21   33270   (null)            (null)          MZRFEHLER#-1     0                     MDB        Protection#0         (null)         F55192  2020-01-01  (null)                   (null)                  0                     (null)               CorresLang#D      2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834479    381527353  6049815982  (null)             37287763           SZMZR#67  (null)     F55.192 / E-ADMIN  2021-01-21   33271   (null)            (null)          MZRFEHLER#-1     0                     MDB        Protection#0         (null)         F55192  2020-12-01  (null)                   (null)                  0                     (null)               CorresLang#D      2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
6049834486    381527353  6049815982  (null)             37287763           SZMZR#67  (null)     F55.192 / E-ADMIN  2021-01-21   33272   (null)            (null)          MZRFEHLER#-1     0                     MDB        Protection#0         (null)         F55192  2020-07-01  (null)                   (null)                  0                     (null)               CorresLang#D      2021-01-21 13:24:48  2021-01-21 13:24:48  ZHIK0A01     IK:EA.N001-V2  I          
*/
select * from vista.jikinsurancerequest where tikviooid in (select tikviooid from vista.jikvaikrequest where tikvaikreqid in (select tikvaikreqid from vista.jikrequestheader where pendvnr = '7561976268274' and program like 'IK:EA.N001_V2') and operation='I') and operation='I';
/*
TIKVIOOID   CUSTOMER    CORRESPONCEADDRESSID  BPRINTID  BZASCOMPLETED  PRINTORDERDATE  VISTADOCREF  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM        OPERATION  
----------  ----------  --------------------  --------  -------------  --------------  -----------  -------------------  -------------------  -----------  -------------  ---------  
6049815982  1856932615  37287763              0         0              (null)          (null)       2021-01-21 13:13:30  2021-01-21 13:13:30  ZHIK0A01     IK:EA.N001-V2  I          
*/
select * from vista.tpvrole where kpvroleid=1856932615; -- STA
select * from vista.tpvpartner where kpvpartid=1856932613; -- Universität Zürich
select * from vista.tikemployerarchive where kpvpartner=1856932613 and billnbr='F55192';
/*
TIKEARCID   BILLNBR  BILLNBROLD  CBRANCHCODE  ADR1                ADR2    ADR3            ADR4         KPVCORRADDRESS  UID           CREGISTERCODE    CLEGALFORM    CEADMINCODE   VALIDFROM   VALIDTO     BWREGISTEROID                         KPVPARTNER  KPVCORRPARTNER  KPVREGISTERADDRESSREPL  KPVCORRADDRESSREPL  KPVREGISTERADDRESS  CSPECIALCODE   TOWNSHIP  CMEMBERTYPE   LASTUPDATED          
----------  -------  ----------  -----------  ------------------  ------  --------------  -----------  --------------  ------------  ---------------  ------------  ------------  ----------  ----------  ------------------------------------  ----------  --------------  ----------------------  ------------------  ------------------  -------------  --------  ------------  -------------------  
1224588594  F55192   (null)      BRANCHE#85   Universität Zürich  (null)  Rämistrasse 74  8001 Zürich  37287763        CHE115665634  ERFASSTCOD#MGAG  RECHTSFORM#N  EADMINCODE#J  2000-01-01  9999-12-31  150737db-a739-4d46-a05f-862c2b3b511c  1856932613  25112737        (null)                  (null)              1856933094          SONDERFALL#03  963169    MEMBERTYP#AK  2019-09-20 22:01:33  
*/

-- 	Defect 40105: [ifix] IK_OS_Dopix -  VNRNAME is sometimes not set on KOBR although existing on collection and ELAR template tag is wrong_40105
select * from vista.tikcollection where tikcollid=2620072236;
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE  CSZ       VNR            VNRNAME                  VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE  ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          
----------  ---------  ----------  ----------  ----------  --------  --------  -------------  -----------------------  -------------  -----------  -----------  ------------  ----------------  ---------  -------------------  ---------  ------------------  --------  ---------------  -------------------  
2620072236  681886880  2021-04-29  17          0           SGSIT048  SZMZR#97  7560911702026  TSCHUEMPERLIN,CHRISTIAN  (null)         (null)       (null)       2021-04-29    (null)            (null)     VDR1907190021087017  13069976   N                   J         (null)           2021-04-29 08:27:02  
*/
select * from vista.tikzikexecution where tikzexcid=2620072232;
/*
TIKZEXCID   TIKZIORID   TIKSEXCID_LEAD1  TIKSEXCID_LEAD2  TIKCOLLID_ACTUAL  TRANSMISSIONDATE  BADDENDUMIK  BMANRELEASEREQUIRED  NBRAK  NBRBO  VNR            VNRNAME                  BMANUALLYADDEDEXECUTION  BMANUALLYADDEDBOOKING  BSPLITTINGDONE  EXECUTIONDATE  EXECUTEDBY  EXBYBATCH  ENTRANCEDATE  BTRANSMISSIONDATESETMANUALLY  LASTUPDATED          
----------  ----------  ---------------  ---------------  ----------------  ----------------  -----------  -------------------  -----  -----  -------------  -----------------------  -----------------------  ---------------------  --------------  -------------  ----------  ---------  ------------  ----------------------------  -------------------  
2620072232  2620072401  (null)           (null)           2620072236        2021-04-29        0            0                    17     0      89870442212    TSCHUEMPERLIN,CHRISTIAN  0                        0                      0               2021-04-29     SGIK0A01    1          2021-04-29    0                             2021-04-29 08:28:33  
*/

select * from vista.jikzikrequest where vnrla='7560911702026' or vnrla='89870442212' or vnrla='7562542597583'; -- empty
/*
TIKZIKREQID  KPVROLEID  CORRESPONCEADDRESSID  CSZ       AKNOTICE  REQUESTDATE  MZRNBR  TRANSMISSIONDATE  ACCEPTANCEDATE  CPROCESSINGCODE  BPOBASKETENTRYCLOSED  CREATEDBY  CLOSINGDATE  CRESIDANCECODE  CCODELA       VNRLA          VNRLANAME  VISTADOCREF          DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                      OPERATION  
-----------  ---------  --------------------  --------  --------  -----------  ------  ----------------  --------------  ---------------  --------------------  ---------  -----------  --------------  ------------  -------------  ---------  -------------------  ------------------  --------  ---------------  -------------------  -------------------  -----------  -------------------------------------------  ---------  
2314221000   71961333   (null)                SZMZR#92  SGBFR     2020-01-14   758313  (null)            (null)          MZRFEHLER#-1     (null)                sgbfr      (null)       (null)          SZLEISTANS#1  7562542597583  (null)     VDR1408200019173228  N                   N         (null)           2020-01-14 08:39:02  2020-01-14 08:39:02  sgbfr        IK:APP129_IK-Dlg-205_Order_IK_Extract_ZAS_e  I          
2314221000   71961333   (null)                SZMZR#92  SGBFR     2020-01-14   758313  (null)            (null)          MZRFEHLER#-1     (null)                sgbfr      (null)       (null)          SZLEISTANS#1  7562542597583  (null)     VDR1408200019173228  N                   N         (null)           2020-01-14 08:39:02  2020-01-14 16:01:08  SGIK0A01     IK:IKJB10101D:2314586610                     U          
2314221000   71961333   (null)                SZMZR#92  SGBFR     2020-01-14   758313  2020-01-14        (null)          MZRFEHLER#-2     (null)                sgbfr      (null)       (null)          SZLEISTANS#1  7562542597583  (null)     VDR1408200019173228  N                   N         (null)           2020-01-14 16:01:08  2020-01-15 20:27:18  SGIK0A01     IK:IKJMEBB102:2315573184                     U          
2314221000   71961333   (null)                SZMZR#92  SGBFR     2020-01-14   758313  2020-01-14        2020-01-14      MZRFEHLER#0      (null)                sgbfr      (null)       (null)          SZLEISTANS#1  7562542597583  (null)     VDR1408200019173228  N                   N         (null)           2020-01-15 20:27:18  2020-01-15 20:29:23  SGIK0A01     IK:IKJB11101:2315602412                      D          
*/
select * from vista.jikzikrequest where vistadocref='VDR6013260000036823' or vistadocref='2111902620079115'; -- empty

select * from vista.tikzikorder where tikziorid=2620072401;
/*
TIKZIORID   TIKZIORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE  VNR            VNRNAME                  VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           CRESIDANCECODE  VNRLA          VNRLANAME                CONTRIBUTIONPERIODFROM  CONTRIBUTIONPERIODUNTIL  LASTUPDATED          
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  --------  -------------  -----------------------  -------------  ----------------  -----------  ------------------  --------------  -------------  -----------------------  ----------------------  -----------------------  -------------------  
2620072401  (null)             79726521   2021-04-29  SZMZR#97  17          0           0               17          0           SGSIT048  89870442212    TSCHUEMPERLIN,CHRISTIAN  (null)         2021-04-29        2021-12-01   ZAS                 (null)          7560911702026  TSCHUEMPERLIN,CHRISTIAN  (null)                  (null)                   2021-04-29 08:27:37  
*/

-- Working case: Suter Anton
select * from vista.tikcollection where tikcollid=2620078377;
/*
TIKCOLLID   TIKHEADID  ORDERDATE   ORDERINGAK  ORDERINGBO  AKNOTICE  CSZ       VNR            VNRNAME      VNRBEFORE1972  CLOSINGDATE  VNRLASPOUSE  ENTRANCEDATE  TRANSMISSIONDATE  KPVRRELID  VISTADOCREF          KPVADRSID  DELIVERYTHIRDPARTY  AUTOSEND  TIKDELADDRESSID  LASTUPDATED          
----------  ---------  ----------  ----------  ----------  --------  --------  -------------  -----------  -------------  -----------  -----------  ------------  ----------------  ---------  -------------------  ---------  ------------------  --------  ---------------  -------------------  
2620078377  80910804   2021-04-29  17          0           SGSIT048  SZMZR#97  7562542597583  SUTER,ANTON  (null)         (null)       (null)       2021-04-29    (null)            (null)     VDR1907220021087020  (null)     J                   J         2620067774       2021-04-29 09:57:07  
*/


-- IK.2021.89554 - SEDEX for KSTA
select * from vista.tzaxmlsdxrecord where messagetype=2050;
-- prodTI:
/*
    <ns3:senderId>6-321000-1</ns3:senderId>
    <ns3:recipientId>6-021000-1</ns3:recipientId>
*/
-- SIT430 (SG):
/*
    <senderId>6-311000-1</senderId>
    <recipientId>6-011000-1</recipientId>
*/ 
select * from vista.tikkoaurequest where senderid='SEDEX';


-- TEI-Rolle
select r.*, p.cpartnertype from vista.tpvrole r left join vista.tpvpartner p on (p.kpvpartid = r.kpvpartid) where r.croletype='Rolle#TEI'; -- ZH: very old from 2008 migration.
select * from vista.tpvparticipatorrel;
/*
TPVPCPTID  KPVPARTID  KPVROLEID  CRELATIONTYPE   RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ---------  ---------  --------------  -------------  -----------  -------------------  
44022095   25617784   44022094   JointPartn#KOL  1996-09-03     9999-12-31   2008-10-23 17:20:20  
44022099   25617784   44022098   JointPartn#KOL  1996-09-03     9999-12-31   2008-10-23 17:20:20  
*/

-- KEP GoesTo Country
select * from vista.tpvkeppb;
select * from vista.tpvkeppb where ktocountryiso is not null order by lastupdated desc; -- KPGT, e.g. tpvkepprocid = 6554703832, tpvkeppartid = 6554707652
select * from vista.tpvkeppb where ktocountryiso is not null and tpvkepprocid = 6554703832 and tpvkeppartid = 6554707652 order by lastupdated desc; -- KPGT, e.g. tpvkepprocid = 6554703832, tpvkeppartid = 6554707652
select * from vista.tpvkeppartner where tpvkeppartid = 6554707652;
select * from vista.tpvkepaddress where tpvkeppartid = 6554707652;
select * from vista.tpvkepfamilyrel where tpvkepprocid = 6554703832 and tpvkeppartid_source = 6554707652; -- empty
select * from vista.tpvkepprocessing where tpvkepprocid = 6554703832;
select * from vista.tzaxmlsdxrecord where messagetype in (1118, 10099) and lastupdated > '2021-05-26'; 
select * from vista.kpvpartner where kpvpartid=2310507208;
select * from vista.tpvpartner where kpvpartid=2310507208;
select * from vista.tpvelarpid where kpvpartid=2310507208;
-- Korea-Case:
SELECT * FROM vista.TPVKEPADDRESS WHERE tpvkeppartid=6523136587;

-- Arrival / Moving
select * from vista.tpvkeppb pb where pb.varrivaldate is not null; -- viele
select * from vista.tpvkeppb pb where pb.darrivaldate is not null; -- empty
select * from vista.tpvkeppb pb where pb.vmovingdate is not null; -- viele
select * from vista.tpvkeppb pb where pb.dmovingdate is not null; -- empty

-- QR-IBANs
select * from vista.tpvpaymentaddr where iban like 'CH%' and substr(iban, 3, 1) = '3';
select count(kpvpaddid) from vista.tpvpaymentaddr where iban like 'CH%' and substr(iban, 3, 1) = '3'; -- 123'690 ZH
select * from vista.tpvpaymentaddr where iban like 'CH%' and substr(iban, 5, 1) = '3';
select count(kpvpaddid) from vista.tpvpaymentaddr where iban like 'CH%' and substr(iban, 5, 1) = '3'; -- 27 ZH
select p.* from vista.tpvpaymentaddr pa
left join vista.tpvpartner p on p.kpvpartid = pa.kpvpartid
where pa.iban like 'CH%' and substr(iban, 5, 1) = '3';
select kpvbankid, clearingnr, bankname from vista.tpvbankbasic where clearingnr like '3%' and ccountry='Country#CH' and validto > current date;
/*
KPVBANKID   CLEARINGNR  BANKNAME                    
----------  ----------  --------------------------  
5483128845  30700       Zürcher Kantonalbank        
5569648034  31000       Credit Suisse (Schweiz) AG  
5581994239  30808       Raiffeisen                  
6110827949  30220       VP Bank (Schweiz) AG        
6273895157  30024       Valiant Bank AG             
6407318185  30000       Postfinance AG              
*/
select * from vista.tpvpaymentaddr where iban like 'LI%' and substr(iban, 5, 1) = '3';
select * from vista.tpvbankbasic where kpvbankid=373635706;
select * from vista.tpvpaymentaddr where left(iban, 2) <> 'LI' and substr(iban, 5, 1) = '3';
select * from vista.tpvbankbasic where kpvbankid=1866352;

-- Defect 40901: IK.2020.78479 for splitting orders for fusioned AKs with multiple splittings (different periods) only one dummy Splitting is created
-- SIT401
select * from vista.tikheader where vnr in ('7569735004514', '7561594015830'); -- ownrid = 400838438, 400840107
select * from vista.tikowner where tikownrid in (400838438, 400840107); -- kpvroleid = 377306830, 377322047
select * from vista.tpvpartner where personid in ('7569735004514', '7561594015830');
-- Neuer Fall Silvia:
select * from vista.tikheader where vnr in ('7564122975866', '21462802150') or tikownrid = 400843381; -- ownrid = 400843381
select * from vista.tikowner where tikownrid in (400843381); -- kpvroleid = 377323364
select * from vista.tpvpartner where personid in ('7564122975866');

select * from vista.tikzikexecution where TIKSEXCID_LEAD1 in (select tiksexcid from vista.tiksplittingexecution where TIKSPORID in (select TIKSPORID from vista.tiksplittingorder where vnr in('72977811113','43662802116','21462802150', '7564122975866')));

-- KEP - GoesTo
select * from vista.tpvkepaddress where (tocountryiso is not null or tocountryname is not null);
select * from vista.tpvkepaddress where (tocountryiso is not null or tocountryname is not null) and tomunicipalityname is not null; -- empty
select * from vista.tpvkepaddress where (tocountryname = 'Schweiz'); -- empty

-- KEP - 55.9 - Guardians
select * from vista.TPVKEPFAMILYREL
where TYPEOFREL > '6';


select distinct clastaction from vista.tikbooking;

-- REQ-Estimation BGS (Beitragsgutschriften)
select * from vista.tikcarer order by lastupdated desc;
select * from vista.tikcaretakingbonus order by lastupdated desc; -- 9000010002150001
select * from vista.tpvrole order by lastupdated desc; -- 7101687 -- kpvpartid = 167913487
select * from vista.tpvpartner where kpvpartid=167913487; -- Fournier Anna
select * from vista.tpvpart_tikctbo order by lastupdated desc;
select * from vista.tpvrole where kpvroleid=9000010002150001; --- 9000010001050001
select * from vista.tpvpartner where kpvpartid=9000010001050001; -- KnoblochX_IK


-- PV.2021.91361	ECM: Testdaten für AIT701
-- 1a) NNP-Employers (Firma)
select * from vista.tikemployerarchive where uid is not null and validfrom < '2000-01-01';
select distinct ea.tikearcid, ea.billnbr, ea.cbranchcode, ea.adr1, ea.adr4, ea.uid, ea.cregistercode, ea.clegalform, ea.ceadmincode, ea.validfrom, ea.validto, ea.kpvpartner, ea.kpvcorrpartner, ea.kpvregisteraddress,
p.cpartnertype, a.caddresstype 
from vista.tikemployerarchive ea
left join vista.tpvpartner p on (p.kpvpartid = ea.kpvpartner)
left join vista.tpvaddress a on (a.kpvadrsid = ea.kpvregisteraddress)
where ea.validfrom < '2000-01-01' and ea.validto = '9999-12-31' and p.cpartnertype = 'PartnerTyp#NP' and ea.cregistercode is not null;
-- ZH:
-- 6288199399 Compositas GmbH
-- 2700293334 Studio Sito Architekten GmbH
-- 1224221966 Pogo GmbH
-- SG:
-- 597099717 G + P Engineering AG
-- 597100382 Filou Line AG
-- 597100949 Fremo AG

-- 1b) NP-Employers
-- 597046620 Moser ERFASSTCOD#MGPBSE
-- 596621048 Keller ERFASSTCOD#MGPBSE
-- 596621585 Frei ERFASSTCOD#MGPBNE
-- 596622598 Saxer Waser ERFASSTCOD#MGAG
select * from vista.aurupiregister where new_nnss in (
    select distinct personid from vista.tpvpartner where personid is not null and kpvpartid in (
        select coalesce(kpvpartner, -1) from vista.tikemployerarchive where tikearcid in(597046620, 596621048, 596621585, 596622598)
    )
) with UR;

select * from vista.aurupiregister where new_nnss in ('7562582756148');
select * from vista.aurupiregister where new_nnss in (-1);

-- 2) NPs
select distinct p.kpvpartid, p.name, p.personid, p.validfrom, p.validto,
a.caddresstype, r.croletype
from vista.tpvpartner p
join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31')
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#RE', 'Rolle#EL'))
where p.cpartnertype = 'PartnerTyp#NP';
-- 957116 Schwimmbeck, AA, WS, RE, EL
-- 957835 Jost-Sieber, WS, RE
-- 958171 Schmid, WS, EL

select * from vista.aurupiregister where new_nnss in (
    select distinct personid from vista.tpvpartner where personid is not null and kpvpartid in (957116, 957370, 957835, 958171, 8621637)
) with UR;

-- 3) Familien
select distinct p.kpvpartid, p.name, p.personid, p.validfrom, p.validto,
a.caddresstype, r.croletype, fr.crelationtype, fr.kpvpartid_target
from vista.tpvpartner p
join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31')
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#RE', 'Rolle#EL'))
join vista.tpvfamilyrel fr on (fr.kpvpartid_source = p.kpvpartid)
where p.cpartnertype = 'PartnerTyp#NP';
-- 957370 Oettli EP + 8621637

-- MQ-Tests (AIT101):
select * from vista.tsfmqoutbound outb where jmstype='BZ.PV-I003' and outb.lastupdated >= current timestamp - 1 DAY order by lastupdated desc; --where key1 = 5833498328 or key2=5833498328; -- empty

-- CC:
-- BZ.PV-I003_TC_specific.txt:
-- PARTNER;U;1295608;1295608;
select * from vista.tpvpartner where kpvpartid=1295608;
-- Local:
-- BZ.PV-I003_simple.txt:
--PARTNER;U;9500000000323109;9500000000323109;

select outb.REASON, count, date(outb.LASTUPDATED)
from vista.TSFMQOUTBOUND outb
where outb.REASON is not NULL AND jmstype= 'BZ.PV-I003'
and outb.LASTUPDATED >= current timestamp - 1 DAY
group by date(outb.LASTUPDATED), outb.REASON;

-- MQ-Tests (AIT101):
select * from vista.tsfmqoutbound outb where jmstype='LZ.PV-RR003' and outb.lastupdated >= current timestamp - 1 DAY order by lastupdated desc;



---
select * from vista.aurupiregister;
update VISTA.TURUPIREGISTER set NAME = 'BLUMER,JOLANDA3' WHERE TURUPIREGISTERID = 523838853;

select * from VISTA.KPVADDRESSBASIC where kpvadbaid in ( 
 (12885), 
 (39860), 
 (78736), 
 (141395), 
 (207715), 
 (222791), 
 (249846), 
 (261493), 
 (327641), 
 (385167), 
 (401573), 
 (403825), 
 (493540), 
 (513996), 
 (537630), 
 (596062), 
 (666767), 
 (840008), 
 (910639) ); -- 

-- AIT701: 910639 existiert

select * from vista.tpvaddressbasic where kpvadbaid=910639;
select * from vista.tpvaddressbasic where kpvadbaid=910640; -- empty
select * from vista.tpvaddressbasic where tpvadbaid in (
    12884,  39856,  78734,  141394, 207714, 222790, 249844, 261492, 327640, 385166, 385184, 401569, 403823, 493537, 513994, 537628, 596059, 666766, 840006, 910634
); -- 910634
select * from vista.tpvaddressbasic where tpvadbaid = 910635; -- empty
select * from vista.aurupiregister where new_nnss in ('7563902522849', '7562733034200', '7568010651719', '7562582756148', '7562582756148', '7562733034200', '7562733034200', '7563902522849', '7563902522849', '7568010651719', '7568010651719', '7562582756148', '7562582756148');

select * from vista.aurupiregister where new_nnss in ('7564273851705');

-- Banken in TI / Filialen:
select * from vista.tpvbankbasic where kpvbankid in (866466, 1000933395);
select kpvbankid, '236' as clearingnr, count(*) as cnt_accounts from vista.tpvpaymentaddr where kpvbankid in (866466, 1000933395) group by kpvbankid;
select b.kpvbankid, b.clearingnr, b.swiftnr, b.bankname, b.address1, b.city, (select count(*) from vista.tpvpaymentaddr pa where pa.kpvbankid = b.kpvbankid) as cnt_accounts
from vista.tpvbankbasic b where b.kpvbankid in (866466, 1000933395, 867058, 1000928272, 858854, 1000739896, 1000934121, 857326, 1000932619, 866719, 1001174128, 857552, 1001174131, 860854, 1000932631)
and b.validto > current date order by b.clearingnr asc;

-- 257443 - ZH - Gemeindefusion (Tresa TI)
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (5178, 5202, 5222, 5213, 5239) or ahvbranchnr in (-1, -2)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
-- EDU:
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311898110, 3311898625, 3311898918, 3311899067) or 
    t.kpvpartid_taxdomicile in (3311898110, 3311898625, 3311898918, 3311899067) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;


-- 257800 - ZH - Gemeindefusion (Val de Bagnes)
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (6031, 6036, 6037) or ahvbranchnr in (-1, -2)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;
-- EDU
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311902997, 3311903057) or 
    t.kpvpartid_taxdomicile in (3311902997, 3311903057) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;

select count(*) from vista.tpvaddress where kpvpartid_munauthor in (3311902997, 3311903057) and validto > '2021-01-01'; -- 61
select count(*) from vista.tpvaddress where kpvpartid_munauthor in (3311898110, 3311898625, 3311898918, 3311899067) and validto > '2021-04-17';


-- IK-Minipartner creation
select * from vista.jpvpartner where operation='I' and program like 'IK%';
select distinct(left(program, 12)) as prog from vista.jpvpartner where operation='I' and program like 'IK%';
/*
IK:APP129_IK  
IK:EA.N001-V  
IK:IKJB11102  
IK:IKJB11106  
IK:IKJMEBB10  
IK:IKJUKDB30  
IK:IKJVSB203  
IK:LZ.IK-I00  
IK:null       
*/
select j.*, left(program, 12) as prog from vista.jpvpartner j where operation='I' and left(program, 12)='IK:IKJB11102' or kpvpartid=5695072854; -- 1 case in ZH???
select j.*, left(program, 12) as prog from vista.jpvpartner j where operation='I' and left(program, 12)='IK:IKJB11102' or kpvpartid=5695072854; -- 0 cases in SG, ZG, ...
select program, count(*) as cnt_inserts from vista.jpvpartner where operation='I' and program like 'IK:LZ.IK-I00%' group by program; -- ZH: IK:LZ.IK-I001-V2 = 32
select program, count(*) as cnt_inserts from vista.jpvpartner where operation='I' and program like 'IK:EA.N001-V%' group by program; -- ZH: IK:EA.N001-V2 = 20771
select left(program, 12), count(*) as cnt_inserts from vista.jpvpartner where operation='I' and program like 'IK:IKJB11106%' group by left(program, 12); -- ZH: 233
select left(program, 13), count(*) as cnt_inserts from vista.jpvpartner where operation='I' and program like 'IK:IKJMEBB102%' group by left(program, 13); -- ZH: 255
select j.*, left(program, 13) as prog from vista.jpvpartner j where operation='I' and left(program, 13)='IK:IKJMEBB102';
select j.*, left(program, 13) as prog from vista.jpvpartner j where operation='I' and left(program, 13)='IK:IKJMEBB102' and not exists (
    select 1 from vista.tpvpartner p where p.kpvpartid = j.kpvpartid and p.tpvpartid <> j.tpvpartid
); -- 4, aber Perioden wurden manuell gelöscht:
select * from vista.jpvpartner where kpvpartid in (2957396531, 5699973022, 384208463, 386189383) order by kpvpartid, change_date asc;


-- 258275 - SZ - L&Z IK ZIK71 fehlerhaft
select * from vista.tikheader where vnr='7568901728704'; -- 44276300
select * from vista.tikowner where tikownrid=44276300; -- 43396594
-- ZIK71:
select * from vista.tikzikexecution where tikcollid_actual=873378097; -- excl. 5.0 für 88957848219  
select * from vista.jikzikexecution where tikcollid_actual=873378097; --IK:IKJB11102, IK:IKJVZAB201, IK:IKJB11105
select * from vista.tikbookingdelivered where tikzexcid=873378093; -- 13
select * from vista.jikbookingdelivered where tikzexcid=873378093; -- IK:IKJVZAB201
-- ZIK92: 
select * from vista.tikzikexecution where tikcollid_actual=806719709; -- incl. 5.0 für 88957848219 
select * from vista.jikzikexecution where tikcollid_actual=806719709; --IK:IKJB11102, IK:IKJVZAB201, IK:IKJB11105


-- Defect 93441: IK.2021.78479 zu viele Dummy-Splitting und IKPK_55 bei fusionierte -- SIT401
select * from vista.tikheader where vnr='7561594015830'; -- 400840107
select * from vista.tikowner where tikownrid=400840107; -- 377322047
select * from vista.jikaccount where tikheadid=6588361829;

-- Shortname
select * from vista.tpvemployee order by lastupdated desc;

select * from vista.aurupiregister;


--
select * from vista.tpvpaymentaddr where cpaytype='TypePaymen#I';

-- 42512 - KEP - D-with-stroke
-- 5561972405
select * from vista.tpvpartner where kpvpartid=5561972405;
select * from vista.tzaxmlsdxrecord s where messagetype=1118 and lastupdated >= '2021-07-06' and s.recorddata like '%7564484927633%';
select * from vista.tpvkepprocessing where tpvkepprocid=6616347383; -- 1118
select * from vista.tpvkeppartner where tpvkepprocid=6616347383 and ismainpartner=1 and vn='7564484927633';
select * from vista.tpvkepaddress where tpvkepprocid=6616347383 and tpvkeppartid=6616383092;
select * from vista.tpvkeppb where kpvpartid=5561972405; -- 6616347383

-- AGAP-LI
select * from vista.tpvpartner p where p.cpartnertype='PartnerTyp#NP' and p.csex is null; 
select * from vista.vpvagap where kpvpartid=11352;

DROP VIEW vista.vpvagap;
CREATE VIEW 
    vista.vpvagap 
    ( 
        kpvpartid, peid, name, firstname, birthdate, sex, nationality, deathdate, validfrom, validto 
    ) 
    AS 
    (   SELECT 
            p.kpvpartid, p.personid, p.name, p.firstname, p.birthdate, right(p.csex, 1), replace(p.ccitizenship, 'Country#', ''), p.deathdate, p.validfrom, p.validto
        FROM 
            vista.tpvpartner p 
        WHERE 
            p.cpartnertype='PartnerTyp#NP' and p.validto = (select max(p2.validto) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid) 
    );


-- PV.2021.94036  View für ECM Performancetests
-- searchPartners
/*
Name (always VT_BSTR, case insensitive)	Value type
IDs	SAVEARRAY(BSTR) *
MainName	BSTR
SubName	BSTR
SocialSecurityNumber	BSTR
NewSocialSecurityNumber	BSTR
BillingNumber	BSTR
Appellation	BSTR
Title	BSTR
BirthDate	BSTR
DocumentAuthorization	BSTR
PrivateStreet	BSTR
PrivateStreetNo	BSTR
PrivateZipCode	BSTR
PrivateCity	BSTR
PrivateCountry	BSTR
CompanyStreet	BSTR
CompanyStreetNo	BSTR
CompanyZipCode	BSTR
CompanyCity	BSTR
CompanyCountry	BSTR
PrivateSex	BSTR
PrivateLanguage	BSTR
CompanyLanguage	BSTR
UID	BSTR
*/
select * from vista.tpvpartner;
select * from vista.vpvecmsearchpartner where mainname like 'Hase%' ORDER BY kpvpartid; -- Applecake
select * from vista.tikemployerarchive;

DROP VIEW vista.vpvecmsearchpartner;
CREATE VIEW 
    vista.vpvecmsearchpartner 
    ( 
        kpvpartid, IDs, MainName, SubName, SocialSecurityNumber, NewSocialSecurityNumber, BillingNumber,
        Appellation, Title, BirthDate, DocumentAuthorization, 
        PrivateStreet, PrivateStreetNo, PrivateZipCode, PrivateCity, PrivateCountry, 
        CompanyStreet, CompanyStreetNo, CompanyZipCode, CompanyCity, CompanyCountry,
        PrivateSex, PrivateLanguage, CompanyLanguage, UID 
    ) 
    AS 
    (   SELECT 
            p.kpvpartid, pid.elarpid, p.name, p.firstname, p.socialsecnr, p.personid, ea.billnbr,
            CASE
                WHEN (p.csex = 'Sex#M') THEN 'Herr'
                WHEN (p.csex = 'Sex#W') THEN 'Frau'
                ELSE ''
            END, 
            p.titel, p.birthdate, right(p.cconfidlevel, 1),
            ab_ws.street, a_ws.streetnr, 
            CASE
                WHEN (ab_ws.ccountry in ('Country#CH', 'Country#LI')) THEN left(ab_ws.zip, 4)
                ELSE ab_ws.zip
            END,
            ab_ws.city, replace(ab_ws.ccountry, 'Country#', ''),
            ab_gs.street, a_gs.streetnr, 
            CASE
                WHEN (ab_gs.ccountry in ('Country#CH', 'Country#LI')) THEN left(ab_gs.zip, 4)
                ELSE ab_gs.zip
            END,
            ab_gs.city, replace(ab_gs.ccountry, 'Country#', ''),
            right(p.csex, 1), right(p.clanguage, 1), right(p.clanguage, 1), ea.uid
        FROM 
            vista.tpvpartner p
        LEFT JOIN
            vista.tpvaddress a_ws ON (a_ws.kpvpartid = p.kpvpartid and a_ws.caddresstype = 'AddressTyp#WS' 
            and a_ws.validto = (select max(a2.validto) from vista.tpvaddress a2 where a2.kpvadrsid = a_ws.kpvadrsid))
        LEFT JOIN
            vista.tpvaddressbasic ab_ws ON (ab_ws.kpvadbaid = a_ws.kpvadbaid 
            and ab_ws.validto = (select max(ab2.validto) from vista.tpvaddressbasic ab2 where ab2.kpvadbaid = ab_ws.kpvadbaid))
        LEFT JOIN
            vista.tpvaddress a_gs ON (a_gs.kpvpartid = p.kpvpartid and a_gs.caddresstype = 'AddressTyp#GS'
            and a_gs.validto = (select max(a2.validto) from vista.tpvaddress a2 where a2.kpvadrsid = a_gs.kpvadrsid))
        LEFT JOIN
            vista.tpvaddressbasic ab_gs ON (ab_gs.kpvadbaid = a_gs.kpvadbaid
            and ab_gs.validto = (select max(ab2.validto) from vista.tpvaddressbasic ab2 where ab2.kpvadbaid = ab_gs.kpvadbaid))
        LEFT JOIN
            vista.tikemployerarchive ea ON (ea.kpvpartner = p.kpvpartid 
            and ea.validto = (select max(ea2.validto) from vista.tikemployerarchive ea2 where ea2.kpvpartner = ea.kpvpartner))
        LEFT JOIN
            vista.tpvelarpid pid ON (pid.kpvpartid = p.kpvpartid and pid.default = 1)
        WHERE 
            p.validto = (select max(p2.validto) from vista.tpvpartner p2 where p2.kpvpartid = p.kpvpartid)
    );


-- GW-Beziehungen
select * from vista.jpvfamilyrel where crelationtype='FamilyRela#GW'; -- 15


-- 259256 - ZH - LZPV.I001.BOQ
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and reason is not null order by lastupdated desc; -- 0
-- 1. Stichprobe:
-- <messageDate>2021-07-12T05:48:21.000+02:00</messageDate> 
-- <messageID>d64810af-d13b-4569-82ff-4179cdbd0421</messageID>
-- <businessProcessID>03ebf8b3-0017-4422-9189-3800880341ff</businessProcessID> 
select * from vista.tpvpartner where personid='7567589871931'; -- 11502320
select * from vista.tpvrole where kpvpartid=11502320 and croletype='Rolle#FAK';
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
6707149865  6707149871  11502320   Rolle#FAK  (null)     (null)       N       2006-04-01  9999-12-31  2021-07-14 06:43:05  
*/
select * from vista.jpvrole where kpvpartid=11502320 and croletype='Rolle#FAK';
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM           OPERATION  
----------  ----------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  -------------------  -----------  ----------------  ---------  
5109423901  5109423902  11502320   Rolle#FAK  (null)     (null)       Y       2006-04-01  9999-12-31  2020-01-31 10:21:13  2020-01-31 10:21:13  ZH1014       PV:LZ.PV-I001-V4  I          
5109423901  5109423902  11502320   Rolle#FAK  (null)     (null)       Y       2006-04-01  9999-12-31  2020-01-31 10:21:13  2021-07-14 06:43:05  ZH1290       PV:LZ.PV-I001-V4  D          
6707149865  6707149871  11502320   Rolle#FAK  (null)     (null)       N       2006-04-01  9999-12-31  2021-07-14 06:43:05  2021-07-14 06:43:05  ZH1290       PV:LZ.PV-I001-V4  I          
*/
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated) = '2021-07-12' order by lastupdated asc;
select count(*) from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated) = '2021-07-12' and lastupdated < '2021-07-12 06:00:00'; -- 162
select count(*) from vista.tsfmqinbound where jmstype='LZ.PV-I001' and lastupdated > '2021-07-12 05:00:00' and lastupdated < '2021-07-12 06:00:00'; -- 75
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated) = '2021-07-12' order by lastupdated asc;
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated) = '2021-07-12' and businessprocessid='03ebf8b3-0017-4422-9189-3800880341ff' order by lastupdated asc;
-- XML: FAK / 2006-04-01 - 2021-07-11 / active = 0

-- 2. Stichprobe:
-- <messageID>cf332b8b-0c0d-4438-a813-6998ac8eda1d</messageID>
-- <businessProcessID>7168ae7d-c27c-49a8-b20e-8cb50182ebaf</businessProcessID>
-- <messageDate>2021-07-12T05:49:01.000+02:00</messageDate>
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and date(lastupdated) = '2021-07-12' and businessprocessid='7168ae7d-c27c-49a8-b20e-8cb50182ebaf' order by lastupdated asc;
-- XML: FAKK / 2006-04-01 - 2021-07-11 / active = 0
select * from vista.tpvpartner where personid='7560758021267'; -- 1822843928
select * from vista.tpvrole where kpvpartid=1822843928 and croletype='Rolle#FAKK';
/*
TPVROLEID   KPVROLEID   KPVPARTID   CROLETYPE   BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------  ----------  ---------  -----------  ------  ----------  ----------  -------------------  
6707149867  6707149874  1822843928  Rolle#FAKK  (null)     (null)       N       2006-04-01  9999-12-31  2021-07-14 06:43:05  
*/


-- 260142 - ZH - KJMEBB102
select * from vista.tpvpartner where personid='7562714310484' or socialsecnr='64480621156' or kpvpartid=14431420; -- 14431420
select * from vista.tikheader where vnr='7562714310484'; -- 14431420
/*
TIKHEADID   TIKOWNRID  VNR            NAME          BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ---------  -------------  ------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
6629576990  402570226  7562714310484  MEREU,GLORIA  1980       4           21        SEXCODEZAS#2  BSVLAND#100  64480683151    F                2021-08-02 08:57:43  
*/
select * from vista.tikowner where tikownrid=402570226;
/*
TIKOWNRID  KPVROLEID  LASTUPDATED          
---------  ---------  -------------------  
402570226  382945953  2011-09-24 18:00:19  
*/
select * from vista.tpvrole where kpvroleid=382945953; -- IK: 14431420
/*
TPVROLEID  KPVROLEID  KPVPARTID  CROLETYPE  BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
---------  ---------  ---------  ---------  ---------  -----------  ------  ----------  ----------  -------------------  
382945952  382945953  14431420   Rolle#IK   (null)     (null)       (null)  1980-04-21  9999-12-31  2011-09-24 12:31:42  
*/

select * from vista.aurupiregister where (old_ahv_or_nnss='7562714310484' or new_nnss='7562714310484'); -- and (actualitycd=1 or statuscd > 0);
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME          GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  ------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
1348829909        7562714310484    7562714310484  0         1            MEREU,GLORIA  2         21041980  100            950000    (null)     1              (null)             (null)             (null)         2021-07-07 10:55:10  
1354112295        7564225645598    7562714310484  2         0            ,             0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2021-07-07 10:55:10  */
--> 7564225645598 sistiert

select * from vista.jikheader where vnr='7564225645598'; -- empty
select * from vista.tpvpartner where personid='7564225645598'; -- 385749937
--> 2. Partner exists with outdated NNSS and IK role / IK header!
select * from vista.tpvrole where kpvpartid=385749937; -- IK: 385749943
select * from vista.tikowner where kpvroleid=385749943; -- 403283151
select * from vista.tikheader where tikownrid=403283151; -- 64480683151
/*
TIKHEADID  TIKOWNRID  VNR            NAME          BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
413936984  403283151  64480683151    MEREU,GLORIA  1980       6           21        SEXCODEZAS#2  BSVLAND#218                 T                2011-09-24 19:37:21  
*/  

select * from vista.tzaxmlmzrrecord where datecreated = '2021-08-02'; -- and recorddata like '%VOEGTLIN%';

-- PROD:
select * from vista.tzaxmlmzrrecord where datecreated = '2021-07-29' and recorddata like '%MEREU%'; -- 2
-- EDU:
select * from vista.tzaxmlmzrrecord where datecreated = '2021-08-04'; -- and recorddata like '%MEREU%'; -- 2

-- 260530 - SG - KJMEBB102
-- Key = 2936442032
select * from vista.tzaxmlmzrrecord where datecreated = '2021-08-04';
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=2936442032;
/*
TZAXMLMZRRECORDID  TZKXMLMZRRECORDID  PARENTID  COMPENSATIONFUNDNUMBER  BRANCHOFFICENUMBER  MESSAGETYPE               RECORDDATA                                                                                                                                                 STATE  ENTRYDATE   DATECREATED  LASTUPDATED          
-----------------  -----------------  --------  ----------------------  ------------------  ------------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------  -----  ----------  -----------  -------------------  
2936442032         95422543           (null)    17                      0                   VAIKEmpfangsbestaetigung  <VAIKEmpfangsbestaetigung xmlns:rc="http://www.zas.admin.ch/RC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zas.admin.ch/RC">
            <rc:KasseZweigstelle>017000</rc:KasseZweigstelle>
            <rc:KasseneigenerHinweis>SGWOP/10.058.979</rc:KasseneigenerHinweis>
            <rc:Meldungsnummer>896119</rc:Meldungsnummer>
            <rc:Versichertennummer>7569496316871</rc:Versichertennummer>
            <rc:Versichertennummer13Stellen>7569496316871</rc:Versichertennummer13Stellen>
            <rc:VersichertenAngaben>
                <rc:Namen>CARFORA</rc:Namen>
                <rc:Vornamen>SALVATORE</rc:Vornamen>
                <rc:Geschlecht>1</rc:Geschlecht>
                <rc:Geburtsdatum>1967-02-23</rc:Geburtsdatum>
                <rc:Heimatstaat>218</rc:Heimatstaat>
            </rc:VersichertenAngaben>
            <rc:VersichertenNrBisher>7564864294812</rc:VersichertenNrBisher>
            <rc:MZRSchluesselzahl>33</rc:MZRSchluesselzahl>
            <rc:Verarbeitungscode>0</rc:Verarbeitungscode>
            <rc:Bemerkung1>0</rc:Bemerkung1>
            <rc:Bemerkung2>0</rc:Bemerkung2>
            <rc:Bemerkung3>0</rc:Bemerkung3>
        </VAIKEmpfangsbestaetigung>2      2021-08-02  2021-08-03   2021-08-03 20:24:24  
*/ --> 7569496316871
select * from vista.aurupiregister where (old_ahv_or_nnss='7569496316871' or new_nnss='7569496316871');
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME               GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  -----------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
4611686018506994819  7569496316871    7569496316871  1         1            CARFORA,SALVATORE  1         23021967  218            117000    (null)     (null)         (null)             (null)             2021-08-02     2021-08-03 20:21:15  
4611686018506955656  7564864294812    7569496316871  2         0            ,                  0         01011800  0              (null)    (null)     (null)         (null)             (null)             2021-08-02     2021-08-03 20:19:29  
4611686018506955657  7564864294812    7569496316871  1         0            CARFORA,SALVATORE  1         23021976  218            17000     (null)     (null)         (null)             (null)             2021-08-02     2021-08-03 20:19:29  
*/
select * from vista.tpvpartner where personid in ('7569496316871', '7564864294812') or kpvpartid=2923453861; -- 2923453861
select * from vista.tikheader where vnr in ('7569496316871', '7564864294812');
/*
TIKHEADID   TIKOWNRID   VNR            NAME               BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  -----------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  
2923453872  2923453871  7569496316871  CARFORA,SALVATORE  1967       2           23        SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-07-30 09:14:05  
2860204323  2923453871  7564864294812  CARFORA,SALVATORE  1976       2           23        SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-08-05 10:53:25  
*/
select * from vista.jikheader where vnr in ('7569496316871', '7564864294812');
/*
TIKHEADID   TIKOWNRID   VNR            NAME               BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
----------  ----------  -------------  -----------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
2923453872  2923453871  7569496316871  CARFORA,SALVATORE  1967       2           23        SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-07-30 09:14:05  2021-07-30 09:14:05  sgwop        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
2860204323  2860204322  7564864294812  CARFORA,SALVATORE  1976       2           23        SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-06-02 21:35:22  2021-08-05 10:53:25  SGigsla      IK:APP129_IK-Dlg-306_IK-Concatenation_e  U          
2860204323  2923453871  7564864294812  CARFORA,SALVATORE  1976       2           23        SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-08-05 10:53:25  2021-08-05 10:53:25  SGigsla      IK:APP129_IK-Dlg-306_IK-Concatenation_e  U          
*/
select * from vista.tikowner where tikownrid in (2923453871, 2860204322);
/*
TIKOWNRID   KPVROLEID   LASTUPDATED          
----------  ----------  -------------------  
2923453871  2923453868  2021-08-05 10:53:25  
*/
select * from vista.jikowner where tikownrid in (2923453871, 2860204322); -- deleted Role: 2860204319
select * from vista.jpvrole where kpvroleid=2860204319; -- kpvpartid = 2860204312
select * from vista.jpvpartner where kpvpartid=2860204312; -- *Carfora

-- 260446 - SG - KJMEBB102
-- Key = 2936442032
select * from vista.tzaxmlmzrrecord where datecreated = '2021-08-04';
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=2936442032;

-- 261242 - TI - KJMEBB102
-- Key = 3147699803
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=3147699803; -- 7565421523819 / bisher: 7563730410905
-- STATE = 2, lastupdated = 2021-08-18 20:22:16
select * from vista.aurupiregister where (old_ahv_or_nnss in ('7565421523819', '7563730410905') or new_nnss in ('7565421523819', '7563730410905'));
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME           GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  -------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
4611686018507130146  7563730410905    7565421523819  2         0            ,              0         01011800  0              (null)    (null)     (null)         (null)             (null)             2021-08-17     2021-08-18 20:16:34  
4611686018507130147  7563730410905    7565421523819  1         0            BOTTA,MARTINA  2         01052021  218            21000     (null)     (null)         (null)             (null)             2021-08-17     2021-08-18 20:16:34  
4611686018507131713  7565421523819    7565421523819  1         1            BOTTA,MARTINA  2         15092017  218            117000    (null)     (null)         (null)             (null)             2021-08-17     2021-08-18 20:16:39  
*/
select * from vista.jikheader where vnr in ('7563730410905', '7565421523819');
/*
TIKHEADID   TIKOWNRID   VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
----------  ----------  -------------  -------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
3146328478  3146328477  7565421523819  BOTTA,MARTINA  2017       9           15        SEXCODEZAS#2  BSVLAND#218  (null)    F                2021-08-16 10:21:01  2021-08-16 10:21:01  titas        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
*/
select p.kpvpartid, name, firstname, personid, p.lastupdated, r.croletype from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
where personid in ('7563730410905', '7565421523819') or p.kpvpartid in (1002359275, 3144830046);
/*
KPVPARTID   NAME   FIRSTNAME  PERSONID       LASTUPDATED          
----------  -----  ---------  -------------  -------------------  
1002359275  Botta  Martina    7565421523819  2021-08-11 16:12:37  
3144830046  Botta  Martina    7563730410905  2021-08-13 20:22:53  
*/

-- 261320 - ZH - KJMEBB102
-- Key = 6886604476
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=6886604476; -- 7567561751190 / bisher: 40466151256
-- STATE = 2, lastupdated = 2021-08-19 21:32:39
select * from vista.aurupiregister where (old_ahv_or_nnss in ('7567561751190', '40466151256') or new_nnss in ('7567561751190', '40466151256'));
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME           GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  -------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
2027299968        28966151155      7567561751190  0         0            DORDIEV,TODE   1         20021966  220            (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2029608475        40466151256      7567561751190  0         0            GORGIEV,TODE   1         20021966  249            (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2064281004        7567561751190    7567561751190  0         1            GEORGIEV,TODE  1         20021966  205            955000    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2064281005        7567561751190    7567561751190  0         0            GEORGIEV,TODE  1         20021966  205            2000      (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2070019153        7569201158628    7567561751190  2         0            ,              0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
*/
select * from vista.tikheader where vnr in ('7567561751190', '7569201158628', '40466151256');
/*
TIKHEADID   TIKOWNRID   VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
3523498094  3523498093  7567561751190  GEORGIEV,TODE  1966       2           20        SEXCODEZAS#1  BSVLAND#205  40466151256    T                2021-08-19 21:39:46  
411676259   405834398   40466151256    GORGIEV,TODE   1966       2           20        SEXCODEZAS#1  BSVLAND#999  28966151155    T                2011-09-24 19:16:52
*/
select p.kpvpartid, name, firstname, personid, p.lastupdated, r.croletype from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
where personid in ('7567561751190', '7569201158628') or p.kpvpartid in (399213074, 3523498083);
/*
KPVPARTID   NAME      FIRSTNAME  PERSONID       LASTUPDATED          CROLETYPE  
----------  --------  ---------  -------------  -------------------  ---------  
399213074   Gorgiev   Tode       7569201158628  2013-04-27 16:21:52  Rolle#IK   
3523498083  Georgiev  Tode       7567561751190  2018-09-04 20:43:45  Rolle#IK   
*/

-- 260624 - SG - 756.7366.8368.94 Rückgängigmachung Kasseneigenes Splitting schlägt fehl
select * from vista.tikheader where vnr in ('7567366836894', '7755387250', '11843818384');
/*
TIKHEADID  TIKOWNRID  VNR            NAME                         BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ---------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
80806989   77780692   7567366836894  SAMARDZIC,MUHAREM            1955       9           25        SEXCODEZAS#1  BSVLAND#252  77755387250    F                2020-09-23 20:24:44  
81436552   77903828   11843818384    ANTONIJEVIC-MILOSEVIC,RANKA  1943       10          18        SEXCODEZAS#2  BSVLAND#999  11843818252    F                2010-09-22 13:16:54  
*/
select * from vista.tikowner where tikownrid in (77780692, 77903828); -- kpvroleids: 74943237, 75548460
select * from vista.tpvrole where kpvroleid in (74943237, 75548460);

-- ECM Test:
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 8759653, 8759653, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 4796461, 4796461, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 3394166, 3394166, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 7272731, 7272731, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 10861369, 10861369, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 11142684, 11142684, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 10780732, 10780732, current timestamp);

insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 957116, 957116, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 957370, 957370, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 957835, 957835, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 958171, 958171, current timestamp);
insert into vista.tsfmqevent values (next value for vista.vista_seq, current timestamp, 4, 0, 'PV', 'PARTNER', 'U', 8621637, 8621637, current timestamp);

select * from vista.tsfmqevent order by lastupdated desc;

select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' and lastupdated >= '2021-08-09 13:10:08' order by lastupdated desc; -- 12
select * from vista.tsfmqoutbound where jmstype='BZ.PV-I003' and lastupdated >= '2021-08-09 13:10:08' order by lastupdated desc; -- 12

-- 261006 - prodAR: ASJMAS500D: WI processing Error, error number: 106
select * from vista.tpvpartner where kpvpartid=1541254; -- 7566464556079
select * from vista.tpvpaymentaddr where kpvpartid=1541254;

-- IGS-Defect 96361 - IK.2021.92341 VA/IK Bestellung IK-Dlg-001 - automatische Übernahme der aktiven VNR bei Eingabe einer sistierter VNR
select * from vista.aurupiregister where (old_ahv_or_nnss='7565367673449' or new_nnss='7565367673449');

--
select * from vista.tikheader where vnr='87360441111'; -- 81574501
select * from vista.tikaccount where tikheadid=81574501; -- empty

-- PV.2021.93886 (ÜL PV - Ausländische Zahlungen)
select r.croletype, count(*) as cnt_roles from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source)
where rr.crelationtype='RoleRelati#ZE'
group by r.croletype order by 2 desc;
-- ZH:
/*
CROLETYPE  CNT_ROLES  
---------  ---------  
Rolle#VB   1496044    
Rolle#RE   604148     
Rolle#HE   38869      
Rolle#EL   30481      
Rolle#EMP  683        
Rolle#AS   18         
Rolle#IPV  2          
Rolle#IK   1          
Rolle#STA  1          
*/
-- LI:
/*
CROLETYPE  CNT_ROLES  
---------  ---------  
Rolle#RE   65478      
Rolle#EL   3642       
Rolle#HE   1857       
Rolle#PG   1609       
Rolle#BB   116        
Rolle#EMP  63         
Rolle#AS   6          
Rolle#IK   1          
Rolle#STA  1          
*/
select r.croletype, count(*) as cnt_roles from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source)
left join vista.tpvpaymentaddr pa on (pa.kpvpaddid = rr.kpvpaddid)
where rr.crelationtype='RoleRelati#ZE' and pa.cpaytype='TypePaymen#J'
group by r.croletype order by 2 desc;
-- LI: RoleRels mit Ausland-IBAN:
/*
CROLETYPE  CNT_ROLES  
---------  ---------  
Rolle#RE   14596      
Rolle#EMP  25         
Rolle#EL   10         
Rolle#AS   1          
Rolle#HE   1          
*/

select rr.*, r.croletype from vista.tpvrolerel rr
left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source)
where rr.crelationtype='RoleRelati#ZE';

-- IBAN on AIT
select p.personid, p.kpvpartid, p.name, pa.* from vista.tpvpaymentaddr pa
left join vista.tpvpartner p on (p.kpvpartid = pa.kpvpartid)
where pa.cpaytype='TypePaymen#J';

-- Partner mit IK-Rolle:
select count(*) from vista.tpvrole r left join vista.tpvpartner p on (p.kpvpartid=r.kpvpartid) where r.croletype='Rolle#IK'; -- 3193
-- IK-Konten:
select count(*) from vista.tikaccount; -- 3143
-- IK-Buchungen:
select count(*) from vista.tikbooking; -- 4621
-- Partner mit AS-Rolle:
select count(*) from vista.tpvrole r left join vista.tpvpartner p on (p.kpvpartid=r.kpvpartid) where r.croletype='Rolle#AS'; -- 1615


-- REQ - PIX - KEP
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB')); -- 1'145'277
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB') and (r.active is null or r.active='Y')); -- 457'785
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB') and (r.active is null or r.active='Y') and r.validto >= current date); -- 457'785
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#RE') and (r.active is null or r.active='Y')); -- 320'728
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB', 'Rolle#RE') and (r.active is null or r.active='Y')); -- 754'749
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB', 'Rolle#RE', 'Rolle#HE', 'Rolle#EL', 'Rolle#IVTG') and (r.active is null or r.active='Y')); -- 759'899
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB', 'Rolle#RE', 'Rolle#HE', 'Rolle#EL', 'Rolle#IVTG') and (r.active is null or r.active='Y'))
where p.deathdate is null or p.deathdate < current date - 1 year; -- 759'897 (2 weniger)
select count(distinct p.kpvpartid) from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype in ('Rolle#VB', 'Rolle#RE', 'Rolle#HE', 'Rolle#EL', 'Rolle#IVTG') and (r.active is null or r.active='Y'))
where p.deathdate is null; -- 759'462 (437 weniger)

select * from vista.tzaxmlsdxrecord s where messagetype=1118 and lastupdated >= '2021-08-06';


-- 261376 - TI - KJMEBB102 - Sonderfall: 2 unterschiedliche Personen
-- Key = 3148787167
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=3148787167; -- 7565402951778 / bisher: 7566072951419
-- STATE = 2, lastupdated = 2021-08-20 20:22:33
select * from vista.aurupiregister where (old_ahv_or_nnss in ('7565402951778', '7566072951419') or new_nnss in ('7565402951778', '7566072951419'));
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME                           GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  -----------------------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
2059073760           7566072951419    7566072951419  0         1            FALCONI,GIOVANNI               1         15031976  218            21000     (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
4611686018507100115  7565402951778    7565402951778  1         1            FALCONI,GIOVANNI MASSIMILIANO  1         04121971  218            955000    (null)     (null)         (null)             (null)             2021-08-12     2021-08-14 20:35:01  
4611686018507100116  7565402951778    7565402951778  1         0            FALCONI,GIOVANNI MASSIMILIANO  1         04121971  218            800000    (null)     (null)         (null)             (null)             2021-08-12     2021-08-14 20:35:01  
*/
select * from vista.jikheader where vnr in ('7565402951778', '7566072951419');
/*
TIKHEADID   TIKOWNRID   VNR            NAME                           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL  BHASMINIPARTNER  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                                  OPERATION  
----------  ----------  -------------  -----------------------------  ---------  ----------  --------  ------------  -----------  --------  ---------------  -------------------  -------------------  -----------  ---------------------------------------  ---------  
3147590351  3147590350  7565402951778  FALCONI,GIOVANNI MASSIMILIANO  1971       12          4         SEXCODEZAS#1  BSVLAND#218  (null)    T                2021-08-18 14:18:18  2021-08-18 14:18:18  titas        IK:APP129_IK-Dlg-001_Order-VA_Open-IK_e  I          
*/
select p.kpvpartid, name, firstname, personid, p.lastupdated, r.croletype from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
where personid in ('7565402951778', '7566072951419') or p.kpvpartid in (3147590340, 3142287503);
/*
KPVPARTID   NAME     FIRSTNAME              PERSONID       LASTUPDATED          CROLETYPE  
----------  -------  ---------------------  -------------  -------------------  ---------  
3147590340  Falconi  Giovanni Massimiliano  7565402951778  2021-08-18 14:18:18  Rolle#IK   
3142287503  Falconi  Giovanni               7566072951419  2021-08-06 20:22:45  Rolle#IK   
*/

-- 261380 (gleicher Fall wie 261320) - ZH - KJMEBB102
-- Key = 6886604476
select * from vista.tzaxmlmzrrecord where tzaxmlmzrrecordid=6886604476; -- 7567561751190 / bisher: 40466151256
-- STATE = 2 --> 6, lastupdated = 2021-08-19 21:32:39 --> 2021-08-20 21:33:55
select * from vista.aurupiregister where (old_ahv_or_nnss in ('7567561751190', '40466151256') or new_nnss in ('7567561751190', '40466151256'));
/*
TURUPIREGISTERID  OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME           GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
----------------  ---------------  -------------  --------  -----------  -------------  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
2027299968        28966151155      7567561751190  0         0            DORDIEV,TODE   1         20021966  220            (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2029608475        40466151256      7567561751190  0         0            GORGIEV,TODE   1         20021966  249            (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2064281004        7567561751190    7567561751190  0         1            GEORGIEV,TODE  1         20021966  205            955000    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2064281005        7567561751190    7567561751190  0         0            GEORGIEV,TODE  1         20021966  205            2000      (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
2070019153        7569201158628    7567561751190  2         0            ,              0         01011800  0              (null)    (null)     (null)         (null)             (null)             (null)         2021-08-14 20:15:36  
*/
select * from vista.tikheader where vnr in ('7567561751190', '7569201158628', '40466151256');
/*
TIKHEADID   TIKOWNRID   VNR            NAME           BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
----------  ----------  -------------  -------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
3523498094  3523498093  7567561751190  GEORGIEV,TODE  1966       2           20        SEXCODEZAS#1  BSVLAND#205  40466151256    T                2021-08-19 21:39:46  
411676259   405834398   40466151256    GORGIEV,TODE   1966       2           20        SEXCODEZAS#1  BSVLAND#999  28966151155    T                2011-09-24 19:16:52
*/
select p.kpvpartid, name, firstname, personid, p.lastupdated, r.croletype from vista.tpvpartner p
left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#IK')
where personid in ('7567561751190', '7569201158628') or p.kpvpartid in (399213074, 3523498083);

-- 261611 - TI - Einbürgerung
select count(distinct kpvpartid) from vista.tpvpartner p where p.ccitizenship='Country#CH' and p.ctaxatsource is not null; -- TI: 1763 / ZH: 0 / GE (ML07b): 0

select kpvpartid, tpvpartid, ccitizenship, citizenshipsince, ctaxatsource, validfrom, validto, change_date, program from vista.jpvpartner p where p.kpvpartid in (
    select p2.kpvpartid from vista.tpvpartner p2 where p2.ccitizenship='Country#CH' and p2.ctaxatsource is not null
) order by kpvpartid, change_date desc;

select kpvpartid, tpvpartid, ccitizenship, citizenshipsince, ctaxatsource, validfrom, validto, change_date, program from vista.jpvpartner p where p.kpvpartid in (
    select p2.kpvpartid from vista.tpvpartner p2 where p2.ccitizenship='Country#CH' and p2.ctaxatsource is not null
) union
select kpvpartid, tpvpartid, ccitizenship, citizenshipsince, ctaxatsource, validfrom, validto, null, '[AKTUELL]' from vista.tpvpartner p3 where p3.ccitizenship='Country#CH' and p3.ctaxatsource is not null
order by kpvpartid, change_date desc;

-- AS-Fehler
select tpvpaddid, kpvpaddid, kpvpartid, cpaytype, account, iban, validfrom, validto, sapnr, lastupdated from vista.tpvpaymentaddr where kpvpartid in (3005690, 7506499, 7983539);

-- AHV-Zweigstellen
select count(distinct kpvpartid) from vista.tpvpartner where clegaltype='NNPersonTy#AHVZ'; -- ZH: 202 -- SG: 92 -- GE: 4
select count(distinct kpvpartid) from vista.tpvpartner where clegaltype='NNPersonTy#POLG'; -- ZH: 2250 -- SG: 2283 -- GE: 2927

-- MIG AKSO
select * from vista.tpvpartner where companynr is not null;
select * from vista.tikemployerarchive where uid is not null;
select * from vista.tpvalias;
select kpvpartid, count(*) as cnt_alias from vista.tpvalias group by kpvpartid order by 2 desc;
select * from vista.tpvpartner where kpvpartid=4774352;
select * from vista.tpvaddressbasic where length(street) >= 35;
select ab.street, length(ab.street) as len_street, a.streetnr, length(a.streetnr) as len_streetnr, length(ab.street) + 1 + length(a.streetnr) as len_total
from vista.tpvaddress a
left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
where length(ab.street) + 1 + length(a.streetnr) >= 35 order by 5 desc;
select * from vista.abdpostfilestreet;
select * from vista.tpvpartner where clegaltype like '%#POLG';
select * from vista.tpvaddress;
select * from vista.tpvpartner where clegaltype like '%#AHVZ';
select distinct crelationtype, count(*) as cnt_rel from vista.tpvfamilyrel group by crelationtype;

-- MIG GE:
select count(*) from vista.aurupiregister; -- SIT440: 54'757'591 / ProdSG: 55'795'372

select count(distinct p.kpvpartid) from vista.tpvpartner p where p.personid is not null 
and not exists (select 1 from vista.aurupiregister upi where upi.old_ahv_or_nnss = p.personid or upi.new_nnss = p.personid);

--
/*
SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=310, TABLEID=3, COLNO=1
*/
SELECT C.TABSCHEMA, C.TABNAME, C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = 310
AND T.TABLEID = 3
AND C.COLNO = 1
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME;
/*
TABSCHEMA  TABNAME         COLNAME    
---------  --------------  ---------  
VISTA      TPVPAYMENTADDR  KPVPARTID  
*/
select * from vista.tpvpaymentaddr where iban is not null;


-- SO Migration
select * from vista.tpvbankbasic where ccountry <> 'Country#CH'; -- 49
select count(distinct kpvpaddid) from vista.tpvpaymentaddr where kpvbankid in (select kpvbankid from vista.tpvbankbasic where ccountry <> 'Country#CH'); -- 55
select distinct * from vista.tpvpaymentaddr where kpvbankid in (select kpvbankid from vista.tpvbankbasic where ccountry <> 'Country#CH'); -- 55
select * from vista.tpvaddress where appendix2 not in ('');
select * from vista.tpvaddress where appendix2 > ''; -- 832
select remarks from vista.tpvpartner where remarks > '' and remarks <> 'DATA MIGRATION';
select count(distinct kpvpartid) from vista.tpvpartner where ccountryofliving <> 'Country#CH'; -- 2122
select count(distinct kpvpartid) from vista.tpvpartner where ccountryofliving <> 'Country#CH'; -- 2122
select count(*) from vista.tpvpaymentaddr where cpaytype like '%#B'; -- 152623
select count(distinct pa.kpvpaddid) from vista.tpvpaymentaddr pa 
left join vista.tpvrolerel rr on (rr.kpvpaddid = pa.kpvpaddid)
where pa.cpaytype like '%#B' and rr.kpvpaddid is not null; -- 17355
select count(distinct pa.kpvpaddid) from vista.tpvpaymentaddr pa 
left join vista.tpvrolerel rr on (rr.kpvpaddid = pa.kpvpaddid)
where pa.cpaytype like '%#B' and rr.kpvpaddid is not null and pa.validto > current date; -- 6'911

select * from vista.tpvpartner p where p.cconfidlevel is null;
select * from vista.tpvbankbasic where branchid <> 0;

select p.*, (select count(*)  from vista.tpvpartner

-- 263387 - prodSZ: IG_IK_KOBR_V - OSJPRTSTD - OSWIRESULT#DxError
select fd.REC_IDE, var.PARMNAME, var.VALUE
from dope.dop_fd fd
join dope.dop_fd_var var
on fd.id=var.id
where fd.REC_IDE='2127020400007032314'
---and var.parmname like 'IG_IK%'
with ur;
/*
TIKCOLLID=925768932
KPVPARTID=43312852
NNSS=7568134650636
ZIKEXECUTION=925768925
*/
SELECT * FROM vista.tpvpartner WHERE kpvpartid=43312852;
SELECT * FROM vista.tpvaddress WHERE kpvpartid=43312852; --- keine Adresse IN PV
SELECT * FROM vista.tikcollection WHERE TIKCOLLID =925768932; -- 44611594
select * from vista.tikheader where tikheadid=44611594; -- 44254352
select * from vista.tikowner where tikownrid=44254352; -- kpvroleid = 43312858
select * from vista.jikinsurancerequest where customer=43312858; -- empty
select * from vista.tikkoaurequest; -- empty
select * from vista.jikkoaurequest; -- undefined name
SELECT * FROM vista.TIKDELIVERYADDRESS WHERE TIKDELADDRESSID =925496011; --- sieht okay aus
select * from vista.aurupiregister where old_ahv_or_nnss='7568134650636' or new_nnss='7568134650636';


-- 263224 - LI - GILAI Replication
SELECT CURRENT SERVER AS DB, SERVERNAME, CREATE_TIME, OPTION, SETTING
FROM SYSCAT.SERVEROPTIONS
WHERE OPTION IN ( 'DBNAME' , 'NODE' )
ORDER BY OPTION;
/*
DB        SERVERNAME     CREATE_TIME          OPTION  SETTING   
--------  -------------  -------------------  ------  --------  
VIDPDBLI  ZASDBSERVER    2021-07-24 10:59:29  DBNAME  vidpdbza  
VIDPDBLI  GILAIDBSERVER  2021-07-24 10:18:46  DBNAME  vidpdbex  
VIDPDBLI  ZASDBSERVER    2021-07-24 10:59:29  NODE    vidpinza  
VIDPDBLI  GILAIDBSERVER  2021-07-24 10:18:46  NODE    vidpinli  
*/
select * from vista.AAIREPLICATION rep
where rep.LASTUPDATED >= current timestamp - 30 day order by lastupdated desc;
select * from vista.AAIREPLICATION rep
where rep.LASTUPDATED >= current timestamp - 30 day and cstatus <> 'Status#DONE' order by lastupdated desc;
select * from vista.AAIPARTNER order by taireplicationid desc; -- 430294463
select * from vista.aaireplication where taireplicationid = 430294463;

-- KEP-Analysen
SELECT * FROM vista.tpvpartner WHERE kpvpartid=574146961;

-- KPGT:
select * from vista.tpvkeppb where ktocountryname is not null or ktocountryiso is not null;
select * from vista.tpvkeppb where kpvpartid=3244624464; -- 7563526775621
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-08-05';
-- KPFR:
select * from vista.tpvpartner where kpvpartid=2504457562;
select * from vista.tpvkeppb where kpvpartid=2504457562; -- 7566990256368 --> lastupdated = 2021-08-05 21:35:06
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-08-05'; --> typeOfRelationship = 4 (Father!)
select * from vista.tpvfamilyrel where kpvpartid_source=2504457562; --> target = 14609757 (Mother!)
select * from vista.tpvpartner where kpvpartid=14609757; --> Mother!
-- GR:
select * from vista.tpvkeppb where gr_dtypeofrel is not null;
select count(*) from vista.tpvkeppb where gr_dtypeofrel is not null; -- 572
select count(*) from vista.tpvkeppb where gr_dtypeofrel is not null and gr_kname is not null; -- 58; 


-- Duplicate IBANs
select iban1.kpvpartid, iban1.iban as iban1_iban, iban1.kpvpaddid as iban1_kpvpaddid, iban2.iban as iban2_iban, iban2.kpvpaddid as iban2_kpvpaddid
from vista.tpvpaymentaddr iban1
left join vista.tpvpaymentaddr iban2 on (iban2.kpvpartid = iban1.kpvpartid);

select iban1.kpvpartid, iban1.iban as iban1_iban, iban1.kpvpaddid as iban1_kpvpaddid, iban2.iban as iban2_iban, iban2.kpvpaddid as iban2_kpvpaddid
from vista.tpvpaymentaddr iban1
left join vista.tpvpaymentaddr iban2 on (iban2.kpvpartid = iban1.kpvpartid and iban2.kpvpaddid <> iban1.kpvpaddid);

select iban1.kpvpartid, iban1.iban as iban1_iban, iban1.kpvpaddid as iban1_kpvpaddid, iban2.iban as iban2_iban, iban2.kpvpaddid as iban2_kpvpaddid
from vista.tpvpaymentaddr iban1
left join vista.tpvpaymentaddr iban2 on (iban2.kpvpartid = iban1.kpvpartid and iban2.kpvpaddid <> iban1.kpvpaddid)
where iban1.iban is not null and iban2.iban is not null;

select iban1.kpvpartid, iban1.iban as iban1_iban, iban1.kpvpaddid as iban1_kpvpaddid, iban2.iban as iban2_iban, iban2.kpvpaddid as iban2_kpvpaddid
from vista.tpvpaymentaddr iban1
left join vista.tpvpaymentaddr iban2 on (iban2.kpvpartid = iban1.kpvpartid and iban2.kpvpaddid <> iban1.kpvpaddid and iban2.iban = iban1.iban)
where iban1.iban is not null and iban2.iban is not null;

--> Cross-check:
select * from vista.tpvpaymentaddr iban where iban.kpvpartid=969046; -- prodZH
--> BR_PV_1000821_19

select iban1.kpvpartid, iban1.iban as iban1_iban, iban1.kpvpaddid as iban1_kpvpaddid, iban2.iban as iban2_iban, iban2.kpvpaddid as iban2_kpvpaddid
from vista.tpvpaymentaddr iban1
left join vista.tpvpaymentaddr iban2 on (iban2.kpvpartid = iban1.kpvpartid and iban2.kpvpaddid <> iban1.kpvpaddid and iban2.iban = iban1.iban)
where iban1.iban is not null and iban2.iban is not null and iban1.validto > current date and iban2.validto > current date;

-- Duplicate WS:
select ws1.kpvpartid, ws1.caddresstype as ws1_type, ws1.kpvadrsid as ws1_kpvadrsid, ws2.caddresstype as ws2_type, ws2.kpvadrsid as ws2_kpvadrsid
from vista.tpvaddress ws1
left join vista.tpvaddress ws2 on (ws2.kpvpartid = ws1.kpvpartid and ws2.kpvadrsid <> ws1.kpvadrsid and ws2.caddresstype = ws1.caddresstype)
where ws1.caddresstype is not null and ws2.caddresstype is not null and ws1.validto > current date and ws2.validto > current date;

select ws1.kpvpartid, ws1.caddresstype as ws1_type, ws1.kpvadrsid as ws1_kpvadrsid, ws2.caddresstype as ws2_type, ws2.kpvadrsid as ws2_kpvadrsid
from vista.tpvaddress ws1
left join vista.tpvaddress ws2 on (ws2.kpvpartid = ws1.kpvpartid and ws2.kpvadrsid <> ws1.kpvadrsid and ws2.caddresstype = ws1.caddresstype)
where ws1.caddresstype='AddressTyp#WS' and ws2.caddresstype='AddressTyp#WS' and ws1.validto > current date and ws2.validto > current date;

--> Cross-check:
select * from vista.tpvaddress ws where ws.kpvpartid=999990020069261; -- AIT101

-- MQ Civilstatus:
select kpvpartid, personid, name, ccivilstatus, civilstatussince, validfrom, validto from vista.tpvpartner where ccivilstatus like '%#U';
/*
KPVPARTID         PERSONID       NAME                   CCIVILSTATUS  CIVILSTATUSSINCE  VALIDFROM   VALIDTO     
----------------  -------------  ---------------------  ------------  ----------------  ----------  ----------  
7010522           7569997777355  Kapoor                 Civil stat#U  2000-01-01        2000-01-01  9999-12-31  
30007812          7569998888029  McGonagall             Civil stat#U  1954-01-01        2000-01-01  9999-12-31  
*/

select * from vista.tsfmqoutbound where lastupdated>'2021-10-25 08:00:30' and jmstype='BZ.PV-I003' order by lastupdated desc;

select * from vista.tsfmqinbound where lastupdated>'2021-06-10 08:00:30' and jmstype='BZ.PV-I003' order by lastupdated desc;
select * from vista.tsfmqinbound where lastupdated>'2021-06-10 08:00:30' and jmstype='EA-N001' order by lastupdated desc;
select * from vista.tsfmqevent where lastupdated>'2021-06-10 08:00:30' order by lastupdated desc;

-- KEP-Analysen (SVA-ZH, 28.10.2021)
select * from vista.tzaxmlsdxrecord s where messagetype=1118 and lastupdated >= '2021-08-06';
-- Fall 1: 7560991817764 = 379695002
select * from vista.tpvkeppb pb where pb.kvn='7560991817764'; -- 2 x KPFR, 2021-09-22 + 2021-09-28 
select kpvpartid, pbtype, kvn,kofficialname, kmaritalstatus, vmaritalstatus, dmaritalstatus, lastupdated from vista.tpvkeppb pb where pb.kvn='7560991817764'; -- 2 x KPFR, 2021-09-22 + 2021-09-28 
-- 2021-09-22
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-09-22'; -- XML: 808 messages --> Neue Message mit <eCH-0020:baseDeliveryValidFrom>2021-09-21
select pb.kpvpartid, pb.pbtype, pb.kvn, pb.kofficialname, pb.kmaritalstatus, pb.vmaritalstatus, pb.dmaritalstatus, 
pb.kdateofmaritalstatus, pb.vdateofmaritalstatus, pb.ddateofmaritalstatus, pb.kseparation, pb.vseparation, pb.dseparation
from vista.tpvkeppb pb where pb.kvn='7560991817764' and date(lastupdated)='2021-09-22';
-- 2021-09-28
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-09-28'; -- XML: 5406 messages --> Alte Message mit <eCH-0020:baseDeliveryValidFrom>2016-08-25
select pb.kpvpartid, pb.pbtype, pb.kvn, pb.kofficialname, pb.kmaritalstatus, pb.vmaritalstatus, pb.dmaritalstatus, 
pb.kdateofmaritalstatus, pb.vdateofmaritalstatus, pb.ddateofmaritalstatus, pb.kseparation, pb.vseparation, pb.dseparation
from vista.tpvkeppb pb where pb.kvn='7560991817764' and date(lastupdated)='2021-09-28';
/*
KPVPARTID  PBTYPE  KVN            KOFFICIALNAME  KMARITALSTATUS  VMARITALSTATUS  DMARITALSTATUS  KDATEOFMARITALSTATUS  VDATEOFMARITALSTATUS  DDATEOFMARITALSTATUS  KSEPARATION  VSEPARATION  DSEPARATION  
---------  ------  -------------  -------------  --------------  --------------  --------------  --------------------  --------------------  --------------------  -----------  -----------  -----------  
379695002  KPFR    7560991817764  Ayra Taşçi     4               H               1               2016-05-25            2019-06-20            1                     (null)       U            (null)       
*/
select p.kpvpartid, p.tpvpartid, p.personid as nnss, p.name, p.ccivilstatus, p.civilstatussince, p.cseparation, p.validfrom, p.validto, p.lastupdated from vista.tpvpartner p where p.kpvpartid=379695002;
/*
KPVPARTID  TPVPARTID   NNSS           NAME        CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     LASTUPDATED          
---------  ----------  -------------  ----------  ------------  ----------------  ------------  ----------  ----------  -------------------  
379695002  379695001   7560991817764  Ayra        Civil stat#L  1975-03-14        (null)        1975-03-14  1992-12-07  2015-06-19 12:56:34  
379695002  1752530311  7560991817764  Imren       Civil stat#H  1992-12-08        Separation#U  1992-12-08  2008-12-01  2015-06-19 12:56:59  
379695002  1752530446  7560991817764  Ayra        Civil stat#S  2008-12-02        (null)        2008-12-02  2015-11-10  2016-04-07 09:14:01  
379695002  2194162337  7560991817764  Ayra Tasci  Civil stat#H  2015-11-11        Separation#U  2015-11-11  2016-06-09  2016-12-19 11:54:21  
379695002  2524010879  7560991817764  Ayra        Civil stat#S  2016-05-25        (null)        2016-06-10  2019-06-19  2021-09-29 14:35:13  
379695002  7146413746  7560991817764  Ayra        Civil stat#H  2019-06-20        Separation#U  2019-06-20  2020-09-18  2021-09-29 14:35:34  
379695002  7146414881  7560991817764  Ayra        Civil stat#G  2020-09-19        (null)        2020-09-19  9999-12-31  2021-09-29 14:35:34  
*/
select p.kpvpartid, p.tpvpartid, p.personid as nnss, p.name, p.ccivilstatus, p.civilstatussince, p.cseparation, p.validfrom, p.validto, p.lastupdated, p.change_date 
from vista.jpvpartner p where p.kpvpartid=379695002 and p.tpvpartid=2524010879; -- and p.change_date < '2021-09-29';
/*
KPVPARTID  TPVPARTID   NNSS           NAME  CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     LASTUPDATED          CHANGE_DATE          
---------  ----------  -------------  ----  ------------  ----------------  ------------  ----------  ----------  -------------------  -------------------  
(...)
379695002  2524010879  7560991817764  Ayra  Civil stat#H  2019-06-20        Separation#U  2016-06-10  9999-12-31  2021-09-28 08:36:56  2021-09-29 14:34:45  
*/

-- Fall 2: 7561884913839 = 801078720
select * from vista.tpvkeppb pb where pb.kvn='7561884913839'; -- 2 Meldungen, 1 x ohne PK: (2021-10-13 21:35:08), 1 x KPFR (2021-10-20)
select kpvpartid, pbtype, kvn,kofficialname, kmaritalstatus, vmaritalstatus, dmaritalstatus, lastupdated from vista.tpvkeppb pb where pb.kvn='7561884913839'; 
/*
KPVPARTID  PBTYPE  KVN            KOFFICIALNAME              KMARITALSTATUS  VMARITALSTATUS  DMARITALSTATUS  LASTUPDATED          
---------  ------  -------------  -------------------------  --------------  --------------  --------------  -------------------  
801078720  KPFR    7561884913839  Weldemariam                1               H               1               2021-10-20 21:36:37  
801078720  (null)  7561884913839  Weldemariam Tewoldemedhin  2               H               0               2021-10-13 21:35:08  
*/
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-10-20'; -- XML: 826 messages --> Alte Message mit <eCH-0020:baseDeliveryValidFrom>2019-12-01
select pb.kpvpartid, pb.pbtype, pb.kvn, pb.kofficialname, pb.kmaritalstatus, pb.vmaritalstatus, pb.dmaritalstatus, 
pb.kdateofmaritalstatus, pb.vdateofmaritalstatus, pb.ddateofmaritalstatus, pb.kseparation, pb.vseparation, pb.dseparation
from vista.tpvkeppb pb where pb.kvn='7561884913839' and date(lastupdated)='2021-10-20';
/*
KPVPARTID  PBTYPE  KVN            KOFFICIALNAME  KMARITALSTATUS  VMARITALSTATUS  DMARITALSTATUS  KDATEOFMARITALSTATUS  VDATEOFMARITALSTATUS  DDATEOFMARITALSTATUS  KSEPARATION  VSEPARATION  DSEPARATION  
---------  ------  -------------  -------------  --------------  --------------  --------------  --------------------  --------------------  --------------------  -----------  -----------  -----------  
801078720  KPFR    7561884913839  Weldemariam    1               H               1               1970-09-01            2020-10-22            1                     (null)       U            (null)       
*/
select p.kpvpartid, p.tpvpartid, p.personid as nnss, p.name, p.ccivilstatus, p.civilstatussince, p.cseparation, p.validfrom, p.validto, p.lastupdated from vista.tpvpartner p where p.kpvpartid=801078720;
/*
KPVPARTID  TPVPARTID   NNSS           NAME         CCIVILSTATUS  CIVILSTATUSSINCE  CSEPARATION   VALIDFROM   VALIDTO     LASTUPDATED          
---------  ----------  -------------  -----------  ------------  ----------------  ------------  ----------  ----------  -------------------  
801078720  801078719   7561884913839  Weldemariam  Civil stat#L  1970-09-01        (null)        1970-09-01  2020-10-21  2021-04-15 14:50:06  
801078720  6423351491  7561884913839  Weldemariam  Civil stat#H  2020-10-22        Separation#U  2020-10-22  9999-12-31  2021-04-15 14:52:25  
*/


-- Div. zu KEP:
select datecreated, length(recorddata) as length_recorddata from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated>'2021-06-22' order by 2 desc; 
/*
DATECREATED  LENGTH_RECORDDATA  
-----------  -----------------  
2021-10-15   33198068                     
2021-07-14   11323907                      
2021-07-05   76230              
*/
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-10-15'; -- 1 XML: 5751 messages
select * from vista.tzaxmlsdxrecord where messagetype='1118' and datecreated='2021-07-05'; -- 3 XMLs: 308 + 18 + 13 messages


-- 265531 - ZH - Fehlerhafter PK nach (Dummy-)Splitting (2 Fälle)
/*
Wir haben bei einem Fall ein PK Eintrag erhalten, der aus unserer Sicht fehlerhaft ist.
Bei der IK Buchung am 27. Oktober 2021 wurde ein zweiter Splittingauftrag auf der NNSS (1982 – 2001) mit dem gleichen Auftragsdatum generiert, mit Ausführungsdatum 27.10.2021.
*/
-- Case 1:
/*
Zum ersten Fall:
für die TIKHEADID 409933523, entspricht der Vers.Nr. 234.57.845.316 wurde ein SplittingOrder für die Vers.Nr. 756.0228.9566.93 angelegt.
*/
select * from vista.tikheader where tikheadid=409933523;
/*
TIKHEADID  TIKOWNRID  VNR            NAME                              BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  --------------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
409933523  401322648  23457845316    BUONCOMPAGNI-ACKERMANN,KATHARINA  1957       11          14        SEXCODEZAS#2  BSVLAND#100  10357845144    F                2011-09-24 19:01:51  
*/
select * from vista.tikowner where tikownrid=401322648; -- 378345072
select * from vista.tikbooking where tikbookid=7308365939;
select * from vista.tikperiod where tikbopeid=7308365940;
select * from vista.tikaccount where tikacctid=10000;
select * from vista.jiksplittingorder where tiksporid=7310385607;

-- Case 4:
select * from vista.jiksplittingorder where tiksporid in (7153496000,7153496048); -- vnr = '7568820096014';
/*
TIKSPORID   TIKSPORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE             VNR            VNRNAME          VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           VNRSPOUSE      VISTADOCREF  LASTUPDATED          CHANGE_DATE          CHANGE_USER  PROGRAM                  OPERATION  
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  -------------------  -------------  ---------------  -------------  ----------------  -----------  ------------------  -------------  -----------  -------------------  -------------------  -----------  -----------------------  ---------  
7153496000  (null)             411608379  2003-12-19  SZMZR#95  1           0           0               1           0           VL 1.1/STE/18.12.03  7568820096014  GOJKOVIC,JELENA  403568683      2003-12-19        (null)       FZH091              40359266156    (null)       2021-10-01 21:42:54  2021-10-01 21:42:54  ZHIK0A01     IK:IKJB11103:7153491299  I          
7153496048  (null)             414950603  2003-12-19  SZMZR#95  1           0           0               1           0           VL 1.1/STE/18.12.03  7568820096014  GOJKOVIC,JELENA  72456868       2003-12-19        (null)       FZH091              40359266156    (null)       2021-10-01 21:42:54  2021-10-01 21:42:54  ZHIK0A01     IK:IKJB11103:7153491299  I          
*/
select * from vista.tiksplittingorder where tikheadid in (408595654,409086036,411608373,411608379,411737641,414950603) and orderdate = '19.12.2003';
select * from vista.tikowner where tikownrid in (select distinct tikownrid from vista.tikheader where tikheadid in (408595654,409086036,411608373,411608379,411737641,414950603));

-- Case 2.1: (Retest, 15.12.2021, SIT401)
-- 
select * from vista.tikheader where vnr in ('7567443355942'); -- 408151818
/*
TIKHEADID  TIKOWNRID  VNR            NAME         BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  -----------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
408151818  404917476  7567443355942  CEKIC,FERKA  1954       4           16        SEXCODEZAS#2  BSVLAND#100  25954616617    F                2021-12-14 15:20:03  
*/
select * from vista.tikowner where tikownrid=404917476; -- 404917476 --> role: 395761918
select * from vista.tiksplittingorder where vnr='7567443355942'; -- 3 x insert: IK:IKJB11103:7391479642 @ 2021-12-14 15:38:41
/*
TIKSPORID   TIKSPORID_REVOKED  TIKHEADID  ORDERDATE   CSZ       INVOLVEDAK  INVOLVEDBO  BINTERNALORDER  ORDERINGAK  ORDERINGBO  AKNOTICE   VNR            VNRNAME      VNRBEFORE1972  TRANSMISSIONDATE  CLOSINGDATE  CREATEDBY           VNRSPOUSE      VISTADOCREF  LASTUPDATED          
----------  -----------------  ---------  ----------  --------  ----------  ----------  --------------  ----------  ----------  ---------  -------------  -----------  -------------  ----------------  -----------  ------------------  -------------  -----------  -------------------  
7391479803  (null)             410273452  2008-03-27  SZMZR#95  1           0           0               1           0           VL1.2 GZO  7567443355942  CEKIC,FERKA  259546166      2008-03-27        (null)       FZH781              42962112158    (null)       2021-12-14 15:38:41  
7391479807  (null)             414642315  2008-04-14  SZMZR#95  1           0           0               1           0           VL1.2 GZO  7567443355942  CEKIC,FERKA  706546162      2008-04-14        (null)       FZH781              70660330257    (null)       2021-12-14 15:38:41  
7391479812  (null)             414642312  2008-04-14  SZMZR#95  1           0           0               1           0           VL1.2 GZO  7567443355942  CEKIC,FERKA  70654616       2008-04-14        (null)       FZH781              70660330257    (null)       2021-12-14 15:38:41  
*/

-- Case 2.2:
select * from vista.tikheader where vnr in ('7568820096014'); -- 405669333
/*
TIKHEADID  TIKOWNRID  VNR            NAME             BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  ---------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
408595654  405669333  7568820096014  GOJKOVIC,JELENA  1956       11          28        SEXCODEZAS#2  BSVLAND#252  40356868384    F                2021-12-14 15:22:57  
*/
select * from vista.tikowner where tikownrid=405669333; -- role: 398593561

-- Case 2.3 (SG - SIT417):
select * from vista.tikheader where vnr in ('7563971912619'); -- 76514409
/*
TIKHEADID  TIKOWNRID  VNR            NAME                       BIRTHYEAR  BIRTHMONTH  BIRTHDAY  CSEX          CCOUNTRY     VNRUNTIL       BHASMINIPARTNER  LASTUPDATED          
---------  ---------  -------------  -------------------------  ---------  ----------  --------  ------------  -----------  -------------  ---------------  -------------------  
80018098   76514409   7563971912619  WUEST,BERNADETTE VERONIKA  1957       7           5         SEXCODEZAS#2  BSVLAND#100  74857705118    F                2021-12-14 15:39:41  
*/
select * from vista.tikowner where tikownrid=76514409; -- role: 70418134

-- Case Reg_1 (SG - SIT417) - Regression, hat schon immer funktioniert:
select * from vista.tikheader where vnr in ('7569481792925'); -- 78087288
select * from vista.tikowner where tikownrid=78087288; -- role: 76113939



-- 263787 / 266225 - SG - PV-WP-04 Originalswitch: 7562905615329
-- PID: 447876113802279
-- Unterschiede ProdSG vs. VI-433
select * from vista.tpvelarpid where elarpid='447876113802279';
/*
TPVELHYID  KPVPARTID  ELARPID          DEFAULT  LASTUPDATED          
---------  ---------  ---------------  -------  -------------------  
5347335    5347324    447876113802279  1        2008-06-19 10:15:13  
*/
select * from vista.tpvpartner where kpvpartid=5347324; -- Lindegger
select * from vista.tpvrole where kpvpartid=5347324;
/*
TPVROLEID   KPVROLEID   KPVPARTID  CROLETYPE   BILLINGNR  CCONTRGROUP  ACTIVE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ---------  ----------  ---------  -----------  ------  ----------  ----------  -------------------  
5347328     5347331     5347324    Rolle#STA   (null)     (null)       (null)  1998-08-15  9999-12-31  2008-06-19 10:15:13  
18001693    18001696    5347324    Rolle#MA    (null)     (null)       (null)  1900-01-01  9999-12-31  2008-06-19 14:14:47  
364648775   364648776   5347324    Rolle#IPV   (null)     (null)       (null)  1998-08-15  9999-12-31  2012-01-02 21:48:38  
1370177534  1370177536  5347324    Rolle#IK    (null)     (null)       (null)  2017-12-18  9999-12-31  2017-12-18 20:21:55  
1669416621  1669416622  5347324    Rolle#FAKK  (null)     (null)       Y       2014-07-01  9999-12-31  2018-10-17 17:06:22  
2479154661  2479154662  5347324    Rolle#VB    (null)     (null)       (null)  1998-08-15  9999-12-31  2020-06-25 10:55:10  
*/
select * from vista.tpvaddress where kpvpartid=5347324;
/*
TPVADRSID  KPVPARTID  KPVPARTID_MUNAUTHOR  KPVADBAID  KPVADRSID  CADDRESSTYPE   APPENDIX1  APPENDIX2  CAPPENDIXPOS  STREETNR  UPPERSTREETNR  SECTOR  LOCKED  CSTRUCTURE     CBUSINESSAPP  VALIDFROM   VALIDTO     EXTADDRESSKEY  LASTUPDATED          EGID    EWID    
---------  ---------  -------------------  ---------  ---------  -------------  ---------  ---------  ------------  --------  -------------  ------  ------  -------------  ------------  ----------  ----------  -------------  -------------------  ------  ------  
12608974   5347324    956580               478785     12608976   AddressTyp#WS  (null)     (null)     AppendixPo#V  22        22             (null)  N       AddressStr#CH  (null)        1998-08-15  2000-03-20  (null)         2017-07-26 21:53:16  (null)  (null)  
12608988   5347324    956580               218788     12608976   AddressTyp#WS  (null)     (null)     AppendixPo#V  32        32             (null)  N       AddressStr#CH  (null)        2000-03-21  9999-12-31  (null)         2017-07-26 21:53:16  (null)  (null)  
*/
select kpvrrelid, tpvrrelid, kpvroleid_source, kpvroleid_target, kpvadrsid_corr, crelationtype, ccorraddresseetype, validfrom, validto, lastupdated
from vista.tpvrolerel where kpvroleid_source in (select kpvroleid from vista.tpvrole where kpvpartid=5347324) or kpvroleid_target in (select kpvroleid from vista.tpvrole where kpvpartid=5347324);
/*
KPVRRELID   TPVRRELID   KPVROLEID_SOURCE  KPVROLEID_TARGET  KPVADRSID_CORR  CRELATIONTYPE  CCORRADDRESSEETYPE  VALIDFROM   VALIDTO     LASTUPDATED          
----------  ----------  ----------------  ----------------  --------------  -------------  ------------------  ----------  ----------  -------------------  
2479158218  2479158217  2479154662        5347331           12608976        RoleRelati#KE  Correspond#VBK      2020-06-25  9999-12-31  2020-06-25 10:58:25  
2479158220  2479158219  2479154662        10740589          (null)          RoleRelati#ZE  (null)              2020-06-25  9999-12-31  2020-06-25 10:58:26  
*/
select * from vista.tpvrolerel where ccorraddresseetype='Correspond#IPA'; -- 1
select * from vista.tpvrolerel where ccorraddresseetype='Correspond#IPV'; -- 20
select count(*) from vista.tpvrolerel where ccorraddresseetype like 'Correspond#VB%'; -- 330'754

--
select * from vista.tpvaddressbasic where ccountry not in ('Country#CH', 'Country#LI');
select * from vista.tpvaddressbasic where zip is null;
select * from vista.tpvpartner;

select b.* from vista.tpvaddress a inner join vista.tpvaddressbasic b on a.KPVADBAID = b.KPVADBAID where a.KPVADRSID = 250647354 and b.CCANTON is null and a.VALIDTO >= current date;
select b.* from vista.tpvaddress a inner join vista.tpvaddressbasic b on a.KPVADBAID = b.KPVADBAID where a.KPVADRSID = 1001310074 and b.CCANTON is null and a.VALIDTO >= current date;

select distinct b.* from vista.tpvaddress a inner join vista.tpvaddressbasic b on a.KPVADBAID = b.KPVADBAID where a.KPVADRSID in (250647354, 1001310074) and b.CCANTON is null and a.VALIDTO >= current date;

update vista.tpvaddressbasic set CCANTON ='Canton#TI', lastupdated = current timestamp
where KPVADBAID in (
    select distinct b.KPVADBAID from vista.tpvaddress a inner join vista.tpvaddressbasic b on a.KPVADBAID = b.KPVADBAID 
    where a.KPVADRSID in (250647354, 1001310074) and b.CCANTON is null and a.VALIDTO >= current date
);

--
select * from vista.tpvemployee;


-- KEP-Analysen (Umlaut-Problem)
select * from vista.tzaxmlsdxrecord s where messagetype=1118 and lastupdated = '2021-10-19';
-- Fall 1: 7562499475903 = 1210456787
select * from vista.tpvkeppb pb where pb.kvn='7562499475903'; -- 1 x KPFR
/*
TPVKEPPBID  TPVKEPPROCID  TPVKEPPARTID  MESSAGEID                             KPVPARTID   DOCREF            PR_VVN  PR_KPVPARTID  PBTYPE  KVN            VVN            DVN     KOFFICIALNAME  VOFFICIALNAME  DOFFICIALNAME  KFIRSTNAME  VFIRSTNAME  DFIRSTNAME  KDATEOFBIRTH  VDATEOFBIRTH  DDATEOFBIRTH  KSEX  VSEX  DSEX  KDEATHDATE  VDEATHDATE  DDEATHDATE  KMARITALSTATUS  DMARITALSTATUS  VMARITALSTATUS  VDATEOFMARITALSTATUS  KDATEOFMARITALSTATUS  DDATEOFMARITALSTATUS  KCANCELATIONREASON  VCANCELATIONREASON  DCANCELATIONREASON  KSEPARATION  VSEPARATION  DSEPARATION  KSEPARATIONFROM  VSEPARATIONFROM  DSEPARATIONFROM  KSEPARATIONTILL  KNATIONALITYID  VNATIONALITYID  KNATIONALITYISO  VNATIONALITYISO  KNATIONALITYNAME  VNATIONALITYNAME  DNATIONALITY  KNATIONALITYFROM  VNATIONALITYFROM  DNATIONALITYFROM  KRESIDAUTHOR  VRESIDAUTHOR  DRESIDAUTHOR  KRESIDAUTHORSINCE  VRESIDAUTHORSINCE  DRESIDAUTHORSINCE  KRESIDAUTHORTO  VRESIDAUTHORTO  DRESIDAUTHORTO  KENTRYDATE  VENTRYDATE  DENTRYDATE  MR_KVNTARGET   MR_VVNTARGET   MR_DVNTARGET  MR_KFIRSTNAME  MR_KNAME    MR_VFIRSTNAME  MR_VNAME    MR_KTYPEOFREL  MR_VTYPEOFREL  MR_DTYPEOFREL  PR1_KVNTARGET  PR1_VVNTARGET  PR1_DVNTARGET  PR1_KFIRSTNAME  PR1_KNAME  PR1_VFIRSTNAME  PR1_VNAME  PR1_KTYPEOFREL  PR1_VTYPEOFREL  PR1_DTYPEOFREL  PR1_KCARE  PR1_KVALIDFROM  PR1_VVALIDFROM  PR1_DVALIDFROM  PR2_KFIRSTNAME  PR2_KNAME  PR2_VFIRSTNAME  PR2_VNAME  PR2_KVNTARGET  PR2_VVNTARGET  PR2_DVNTARGET  PR2_KTYPEOFREL  PR2_VTYPEOFREL  PR2_DTYPEOFREL  PR2_KCARE  PR2_KVALIDFROM  PR2_VVALIDFROM  PR2_DVALIDFROM  GR_KTYPEOFREL  GR_VTYPEOFREL  GR_DTYPEOFREL  GR_KFIRSTNAME  GR_KNAME  GR_VFIRSTNAME  GR_VNAME  GR_KCARE  GR_KVALIDFROM  GR_VVALIDFROM  GR_DVALIDFROM  GR_KADDRESSLINE1  GR_VADDRESSLINE1  GR_DADDRESSLINE1  GR_KSTREET  GR_VSTREET  GR_DSTREET  GR_KHOUSENUMBER  GR_VHOUSENUMBER  GR_DHOUSENUMBER  GR_KTOWN  GR_VTOWN  GR_DTOWN  GR_KZIP  GR_VZIP  GR_DZIP  KRESIDENCETYPE  VRESIDENCETYPE  DRESIDENCETYPE  KMUNICIPALITYID  KMUNICIPALITYNAME  KARRIVALDATE  VARRIVALDATE  DARRIVALDATE  KFROMCOUNTRYID  KFROMCOUNTRYISO  KFROMCOUNTRYNAME  KFROMCANTON  KFROMMUNICIPALITYID  KFROMMUNICIPALITYNAME  KDEPARTUREDATE  VDEPARTUREDATE  DDEPARTUREDATE  KTOCOUNTRYID  KTOCOUNTRYISO  KTOCOUNTRYNAME  KTOCANTON  KTOMUNICIPALITYID  KTOMUNICIPALITYNAME  KMOVINGDATE  VMOVINGDATE  DMOVINGDATE  KADDRESSLINE1  VADDRESSLINE1  DADDRESSLINE1  KADDRESSLINE2  VADDRESSLINE2  DADDRESSLINE2  KSTREET  VSTREET  DSTREET  KHOUSENUMBER  VHOUSENUMBER  DHOUSENUMBER  KTOWN       VTOWN       DTOWN  KZIP  VZIP  DZIP  KCOUNTRY  VCOUNTRY  DCOUNTRY  KEGID    VEGID    DEGID  KEWID  VEWID  DEWID  KTYPEOFHOUSEHOLD  STATUS  ERRORMSG  LASTUPDATED          
----------  ------------  ------------  ------------------------------------  ----------  ----------------  ------  ------------  ------  -------------  -------------  ------  -------------  -------------  -------------  ----------  ----------  ----------  ------------  ------------  ------------  ----  ----  ----  ----------  ----------  ----------  --------------  --------------  --------------  --------------------  --------------------  --------------------  ------------------  ------------------  ------------------  -----------  -----------  -----------  ---------------  ---------------  ---------------  ---------------  --------------  --------------  ---------------  ---------------  ----------------  ----------------  ------------  ----------------  ----------------  ----------------  ------------  ------------  ------------  -----------------  -----------------  -----------------  --------------  --------------  --------------  ----------  ----------  ----------  -------------  -------------  ------------  -------------  ----------  -------------  ----------  -------------  -------------  -------------  -------------  -------------  -------------  --------------  ---------  --------------  ---------  --------------  --------------  --------------  ---------  --------------  --------------  --------------  --------------  ---------  --------------  ---------  -------------  -------------  -------------  --------------  --------------  --------------  ---------  --------------  --------------  --------------  -------------  -------------  -------------  -------------  --------  -------------  --------  --------  -------------  -------------  -------------  ----------------  ----------------  ----------------  ----------  ----------  ----------  ---------------  ---------------  ---------------  --------  --------  --------  -------  -------  -------  --------------  --------------  --------------  ---------------  -----------------  ------------  ------------  ------------  --------------  ---------------  ----------------  -----------  -------------------  ---------------------  --------------  --------------  --------------  ------------  -------------  --------------  ---------  -----------------  -------------------  -----------  -----------  -----------  -------------  -------------  -------------  -------------  -------------  -------------  -------  -------  -------  ------------  ------------  ------------  ----------  ----------  -----  ----  ----  ----  --------  --------  --------  -------  -------  -----  -----  -----  -----  ----------------  ------  --------  -------------------  
7261548911  7261467643    7261500406    394c4020-aa82-4b6b-b07e-aa52d521e25c  1210456787  2129207261552683  (null)  (null)        KPFR    7562499475903  7562499475903  (null)  Güvendiren     Güvendiren     0              Sükrü       Suekrue     1           1987-01-07    1987-01-07    0             1     M     0     (null)      (null)      (null)      2               0               H               2012-11-19            2012-11-19            0                     (null)              (null)              (null)              (null)       U            0            (null)           (null)           (null)           (null)           (null)          (null)          TR               TR               Türkei            (null)            0             2013-04-04        1987-01-07        1                 03            B             1             2021-10-14         2020-01-21         (null)             2026-10-03      2021-04-03      (null)          2013-04-04  2013-04-04  0           7566715131192  7566715131192  0             Münire Isik    Güvendiren  Isik           Güvendiren  1              EP             0              (null)         (null)         (null)         (null)          (null)     (null)          (null)     (null)          (null)          (null)          (null)     (null)          (null)          (null)          (null)          (null)     (null)          (null)     (null)         (null)         (null)         (null)          (null)          (null)          (null)     (null)          (null)          (null)          (null)         (null)         (null)         (null)         (null)    (null)         (null)    (null)    (null)         (null)         (null)         (null)            (null)            (null)            (null)      (null)      (null)      (null)           (null)           (null)           (null)    (null)    (null)    (null)   (null)   (null)   0               WS              0               230              Winterthur         2013-04-04    (null)        (null)        8239            TR               Türkei            (null)       (null)               (null)                 (null)          (null)          (null)          (null)        (null)         (null)          (null)     (null)             (null)               (null)       (null)       (null)       (null)         (null)         (null)         (null)         (null)         (null)         Am Buck  Am Buck  0        5             5             0             Winterthur  Winterthur  0      8404  8404  0     CH        CH        0         1154598  1154598  0      6      6      0      1                 P       (null)    2021-10-19 21:36:24  
*/
select * from vista.tpvkeppartner where tpvkeppartid='7261500406'; -- Sükrü
select * from vista.tpvpartner where kpvpartid=1210456787;


-- 263787 - SG - IPV Mutationen Adresse von Vista wird nicht automatisch angezogen

-- 266873 - SG - 73A_12.IVTG_TEV.SH_NP013_000$IVTG_KZLZAS@IGS|RECEIVE_SH_NP013_000$IVTG_KZLZAS|0001499418|ENDED_NOT_OK
select * from vista.tpvpartner where personid='7567145004322'; -- Nagy Gabor (Vater) 306176302 -- 2021-10-13 07:39:26
select * from vista.tpvaddress where kpvpartid=306176302; -- 399091723 -- 2019-12-03 10:21:20
select * from vista.tpvfamilyrel where kpvpartid_target=306176302;
/*
TPVFRELID  KPVPARTID_SOURCE  KPVPARTID_TARGET  CRELATIONTYPE  RELATIONBEGIN  RELATIONEND  LASTUPDATED          
---------  ----------------  ----------------  -------------  -------------  -----------  -------------------  
557116299  557116289         306176302         FamilyRela#LK  2020-11-03     (null)       2020-11-24 11:18:39  
*/
select * from vista.tpvpartner where kpvpartid=557116289; -- Nagy-Bakodi, Zalan (Geb. 2020-11-03) -- 2021-11-23 07:57:27
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' and lastupdated between '2021-11-23 07:57:27' and '2021-11-23 07:59:27' and inboundmsg like '%557116289%'; -- fa76f4bb-9501-4f22-ab31-3f69bfec4afe / 2f5e276a-27be-45d7-b36b-6d4f5e26ec31
select * from vista.tsfmqoutbound where jmscorrelationid in ('fa76f4bb-9501-4f22-ab31-3f69bfec4afe', '2f5e276a-27be-45d7-b36b-6d4f5e26ec31'); --> XMLs

-- Test data improvment
with x as (
    select pa.kpvpartid, pa.kpvpaddid, pa.tpvpaddid, pa.cpaytype, pa.iban, length(pa.iban) as iban_length, 
    right(pa.iban, (length(pa.iban) - 4)) as iban_trunc, b.kpvbankid, b.clearingnr,
    case 
        when length(b.clearingnr) = 3 and b.ccountry = 'Country#CH' then '00' || b.clearingnr
        when length(b.clearingnr) = 4 and b.ccountry = 'Country#CH' then '0' || b.clearingnr
        else b.clearingnr
    end as new_clearing,
    b.ccountry
    from vista.tpvpaymentaddr pa
    left join vista.tpvbankbasic b on (b.kpvbankid = pa.kpvbankid)
    where pa.cpaytype in ('TypePaymen#I', 'TypePaymen#J')
)
select distinct x.*,
case 
   when locate(x.new_clearing, x.iban_trunc) > 0 then 'ok'
   when x.ccountry = 'Country#CH' and x.iban_length <> 21 then 'NOK'
   else 'NOK'
end as iban_ok
from x order by x.kpvpartid, x.kpvpaddid asc;

-- VB:
select rr.*, r.kpvpartid from vista.tpvrolerel rr left join vista.tpvrole r on (r.kpvroleid = rr.kpvroleid_source) where rr.ccorraddresseetype like '%#VB%';

select * from vista.tpvpartner p
join vista.tpvrole r on (r.kpvpartid = p.kpvpartid and r.croletype='Rolle#RE');

-- Anfrage André TI - CreateUpdateRoleRequest - LZ.PV-I001
-- 7568180989629
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and reason is not null order by lastupdated desc; -- 45 x 'MQINBREJ#INVALIDUSR'
select * from vista.tsfmqinbound where jmstype='LZ.PV-I001' and reason is not null and inboundmsg like '%7568180989629%' order by lastupdated desc; -- 9; USERNAME = BATCH
select distinct(jmscorrelationid) from vista.tsfmqinbound where jmstype='LZ.PV-I001' and reason is not null and inboundmsg like '%7568180989629%'; -- nur 1
select distinct(username) from vista.tsfmqinbound where jmstype='LZ.PV-I001';

-- Ticket xxx - AR - Notification
SELECT * FROM vista.THEPVNOTIFICATION where THEPVNOTIFICATIONID = '446693315';
SELECT * FROM vista.THEPVNOTIFICDETAIL where THEPVNOTIFICATIONID = '446693315';
SELECT personid FROM vista.TPVPARTNER where KPVPARTID = 1639760;
-- PERSONID =  7565879594102
SELECT * FROM vista.TPVNOTIFICATION where KPVPARTID_CHANGED = 1639760;
SELECT * FROM vista.jPVNOTIFICATION where KPVPARTID_CHANGED = 1639760 and CTARGETAPPL = 'BusinessAp#HE' order by change_date ASC;
select * from vista.jpvpaymentaddr where kpvpartid=1639760;
select * from vista.tpvpaymentaddr where kpvpartid=1639760;
select * from vista.tpvfamilyrel;


-- 	Defect 46841: IK.2020.78479: Defect: Unnecessary splitting orders and post baskets (dummy splitting)	Retest
-- siehe oben... .

-- Country Kosovo
select ccountry, count(*) as cnt from vista.tpvaddressbasic ab  where ab.ccountry in ('Country#XZ', 'Country#XK') group by ccountry;
/*
CCOUNTRY    CNT  
----------  ---  
Country#XZ  153 
*/
select ccitizenship, count(*) as cnt from vista.tpvpartner p  where p.ccitizenship in ('Country#XZ', 'Country#XK') group by ccitizenship;
/*
CCITIZENSHIP  CNT    
------------  -----  
Country#XZ    49599 
*/
select ccountryofliving, count(*) as cnt from vista.tpvpartner p  where p.ccountryofliving in ('Country#XZ', 'Country#XK') group by ccountryofliving;
/*
CCOUNTRYOFLIVING  CNT  
----------------  ---  
Country#XZ        596  
*/

-- Nur LI:
select ccountry, count(*) as cnt from vista.tpvbankbasic ab  where ab.ccountry in ('Country#XZ', 'Country#XK') group by ccountry;
/*
CCOUNTRY    CNT  
----------  ---  
Country#XK  17   
*/

-- Defect 103622: Fehlermeldung bei Selektion Antragsjahr 2021 / Meldegemeinde Wallisellen: LZ.PV-RR004-V3
--SIT490 Abfrage:
select p.kpvpartid, adr.kpvadrsid, adr.tpvadrsid, adr.caddresstype, adr.streetnr, adr.validfrom, adr.validto, adrb.kpvadbaid, adrb.street, adrb.zip, adrb.city, adrb.ccanton from VISTA.TPVPARTNER p
join VISTA.TPVADDRESS adr on adr.KPVPARTID = p.KPVPARTID
join VISTA.TPVADDRESSBASIC adrb on adrb.KPVADBAID = adr.KPVADBAID
where p.kpvpartid in (
    1050885, 1052801, 1130521, 3585646, 1482561, 2209361, 1578893, 3062551, 2143439, 3051689, 2758025, 1341692, 3172959, 3145360, 1758953, 2277284, 1909470, 1898309, 1315731, 3271969, 3428293, 3521611, 1794883, 2109881, 1711474
)
and p.VALIDTO > current date
--and adr.VALIDTO > current date
--and adrb.VALIDTO > current date
and adr.CADDRESSTYPE = 'AddressTyp#WS'
with ur;

-- Legal representation / guardian
select rr.tpvrrelid, rr.kpvrrelid, rr.crelationtype, rr.clegalguardtype, rr.kpvroleid_source, rs.croletype, rr.kpvroleid_target, rt.croletype from vista.tpvrolerel rr 
left join vista.tpvrole rs on (rs.kpvroleid = rr.kpvroleid_source)
left join vista.tpvrole rt on (rt.kpvroleid = rr.kpvroleid_target)
where rr.crelationtype='RoleRelati#RV' order by rr.lastupdated desc;

select rr.tpvrrelid, rr.kpvrrelid, rr.crelationtype, rr.clegalguardtype, rr.kpvroleid_source, rs.croletype, rr.kpvroleid_target, rt.croletype from vista.tpvrolerel rr 
left join vista.tpvrole rs on (rs.kpvroleid = rr.kpvroleid_source)
left join vista.tpvrole rt on (rt.kpvroleid = rr.kpvroleid_target)
where rr.crelationtype='RoleRelati#GV' order by rr.lastupdated desc;

-- Fabian: NP ohne VNRs
with x as (
    select p.kpvpartid, p.cpartnertype, p.personid, p.socialsecnr, p.name, p.birthdate, r.croletype
    from vista.tpvpartner p 
    left join vista.tpvrole r on (r.kpvpartid = p.kpvpartid)
    where p.cpartnertype = 'PartnerTyp#NP' and p.validto = '31.12.9999' and p.personid is null and p.socialsecnr is null
)
select x.croletype, count(*) as cnt_roles from x group by x.croletype order by 2 desc;

-- 270391 - TG - PVJMAPAI - Unexpected: {0} - UOWManager transaction processing failed - javax.transaction.RollbackException
select * from vista.aaireplication where date(lastupdated) = '2021-12-29'; -- empty
select * from vista.aaireplication where cstatus <> 'Status#DONE'; -- empty

-- 272271 - TI -  PV keine Replika auf B&Z für kpvpartid = 318397
select * from vista.tpvpartner where kpvpartid=318397; -- nnss: 7562123209232
select * from vista.aurupiregister where old_ahv_or_nnss='7562123209232' or new_nnss='7562123209232';
/*
TURUPIREGISTERID     OLD_AHV_OR_NNSS  NEW_NNSS       STATUSCD  ACTUALITYCD  NAME  GENDERCD  BIRTHDAY  NATIONALITYCD  ORIGINCD  DEATHDATE  CIVILSTATUSCD  RELCANCELLATIONCD  CIVILSTATUSCHANGE  DELIVERY_DATE  LASTUPDATED          
-------------------  ---------------  -------------  --------  -----------  ----  --------  --------  -------------  --------  ---------  -------------  -----------------  -----------------  -------------  -------------------  
4611686018510196769  7562123209232    0              3         0            ,     0         01011800  0              (null)    (null)     (null)         (null)             (null)             2022-01-07     2022-01-10 20:16:32  
*/

-- AID
select lastname, birthname, cnamesequence, name from vista.tpvpartner where kpvpartid=167913487;
select birthdate, p.birthdateprec from vista.tpvpartner p where kpvpartid=167913487;

select * from vista.tpvpartner where personid='7567765210622'; -- 1636410
select * from vista.tpvpaymentaddr where kpvpartid=1636410; -- 4010017623
select * from vista.jpvpaymentaddr where kpvpaddid=4010017623;

select * from vista.tpvpartner;
select * from vista.tikemployerarchive;

select * from vista.tpvdynamicparams;

-- ECM - ECM.LZPV.RR003.PARTNER.SEARCH.REP
/*
<igs-1902:PartnerSearch xmlns:igs-1902="https://igs-gmbh.ch/xmlns/igs-1902/3">
    <igs-0006:head xmlns:igs-0006="https://igs-gmbh.ch/xmlns/igs-0006/2">
        <igs-0006:senderId>ECM</igs-0006:senderId>
        <igs-0006:initiatedSenderId>ECM</igs-0006:initiatedSenderId>
        <igs-0006:messageID>ECM</igs-0006:messageID>
        <igs-0006:message>
            <igs-0006:type>igs-1902</igs-0006:type>
            <igs-0006:version>3.0</igs-0006:version>
        </igs-0006:message>
        <igs-0006:sendingApplication>
            <igs-0006:sendingProduct>ECM</igs-0006:sendingProduct>
            <igs-0006:sendingProductVersion>1.0</igs-0006:sendingProductVersion>
        </igs-0006:sendingApplication>
        <igs-0006:messageDate>2022-01-24T15:53:02.681+01:00</igs-0006:messageDate>
        <igs-0006:tenant>ZH</igs-0006:tenant>
    </igs-0006:head>
    <igs-1902:body inWordSearch="false" inPeriodSearch="false" aliasSearch="false" withHistory="false" soundexSearch="false" maxResultsReturned="100">
        <igs-1902:billingNumber>427195</igs-1902:billingNumber>
    </igs-1902:body>
</igs-1902:PartnerSearch>

-- RESPONSE:

<ns2:body statusCode="0" totalResults="0">
    <ns4:fault>
        <ns4:faultcode>MQCANTPROC</ns4:faultcode>
        <ns4:faultstring>be4612354b102] - Error processing output message [Response XML is not valid against its definition.]</ns4:faultstring>
    </ns4:fault>
</ns2:body>
    
*/
-- LZ.PV-RR003
select * from vista.tikemployerarchive where billnbr='427195'; -- kpvpartner: 9000010001200004
select * from vista.tpvpartner where kpvpartid=9000010001200004;
select * from vista.tpvelarpid where kpvpartid=9000010001200004; -- V9000010001200004 
select * from vista.tsfmqoutbound o where o.lastupdated > '2022-01-31' and reason is not null order by o.lastupdated desc; -- MQOUTBREJ#INVOUTXML

select * from vista.tsfmqinbound i where i.lastupdated >= (current date - 0.5 day) and i.jmstype='LZ.PV-RR003' order by i.lastupdated desc;
select * from vista.tsfmqoutbound o where o.lastupdated >= (current date - 0.5 day) and o.jmstype='LZ.PV-RR003' order by o.lastupdated desc;


-- clegaltype = null / clegalform = null
select * from vista.tpvpartner where clegaltype is not null and clegalform is not null; --> clegaltype = NNPersonTy#NNP, clegalform = LegalFormC#VER
select * from vista.jpvpartner where clegaltype is not null and clegalform is not null; --> clegaltype = NNPersonTy#NNP, clegalform = LegalFormC#VER
update vista.tpvpartner set clegaltype = 'NNPersonTy#NNP', clegalform = 'LegalFormC#VER', lastupdated = current timestamp where kpvpartid = 9000010001200004;
select * from vista.tpvpartner where cpartnertype='PartnerTyp#NNP' and clegaltype is null and clegalform is null; --> 447

select * from vista.jpvpartner where clegaltype is not null and clegalform is not null and operation <> 'U'; --> clegaltype = NNPersonTy#NNP, clegalform = LegalFormC#VER

-- GILAI
select count(*) as cnt from vista.aaireplication where lastupdated > '2022-01-01'; -- 26914
select cstatus, count(*) as cnt from vista.aaireplication group by cstatus;

-- Search
select distinct name, namesx from vista.tpvpartner where name like 'Me%';
select * from vista.tpvrole;

-- RoleRels
select * from vista.tpvrolerel order by lastupdated desc; -- Correspond#REK
select * from vista.tpvrole where kpvroleid=2492949850; -- 1057852
select * from vista.tpvrolerel where crelationtype='RoleRelati#GV' order by lastupdated desc;
select * from vista.tpvrole where kpvroleid=1251272553;
select * from vista.tpvrolerel where crelationtype='RoleRelati#RV' order by lastupdated desc;
select * from vista.tpvrole where kpvroleid=423360019;
-- Company Nr.
select * from vista.tpvpartner where companynr is not null; -- SG: 0
select * from vista.tpvpartner where companynr is not null; -- SG: 0
-- AIT Testdata
select count(distinct kpvpartid) as cnt_p from vista.tpvpartner where cpartnertype='PartnerTyp#NNP' and (clegaltype is not null or clegalform is not null); -- 4348
select count(distinct kpvpartid) as cnt_p from vista.tpvpartner where cpartnertype='PartnerTyp#NNP' and (clegaltype is not null and clegalform is not null); -- 2113
-- Fusioned AKs
select kpvpartid, tpvpartid, name, ccompfundtype, compfundnr, compfundbranchnr, compfundfusionnr, compfundfubranr, fusiondate, validfrom, validto from vista.tpvpartner 
where compfundnr = 1 or (compfundfusionnr = 1) order by compfundnr, compfundbranchnr;
-- Repli
select * from vista.tpvdynamicparams;
-- MQ:
select distinct reason, count(*) as cnt_e from vista.tsfmqinbound group by reason order by 2 desc;
/*
REASON              CNT_E    
------------------  -------  
(null)              1579309  
MQINBREJ#INVINPXML  12       
*/
select distinct reason, count(*) as cnt_e from vista.tsfmqoutbound group by reason order by 2 desc;
/*
REASON                CNT_E    
--------------------  -------  
(null)                1243202  
MQOUTINFO#REPNOTREQ   864812   
MQOUTINFO#IGNOREREPL  11130    
MQOUTBREJ#BEANERROR   5826     
MQOUTBREJ#INVOUTXML   244      
*/
select distinct reason, count(*) as cnt_e from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' group by reason order by 2 desc;
select * from vista.tsfmqoutbound o where o.reason='MQOUTINFO#REPNOTREQ';
select distinct reason, count(*) as cnt_e from vista.tsfmqoutbound o where o.jmstype='LZ.PV-I001' group by reason order by 2 desc;
-- Billnbr
select ea.billnbr, ea.kpvpartner, ea.adr1, ea.validfrom, ea.validto from vista.tikemployerarchive ea
join vista.tikemployerarchive ea2 on (ea2.billnbr = ea.billnbr and ea2.kpvpartner <> ea.kpvpartner) order by 1;

select ea.billnbr, ea.kpvpartner, ea.validfrom as ea_validfrom, ea.validto as ea_validto, 
(select min(validfrom) from vista.tpvpartner p where p.kpvpartid = ea.kpvpartner) as p_min_validfrom,
(select max(validto) from vista.tpvpartner p where p.kpvpartid = ea.kpvpartner) as p_max_validto 
from vista.tikemployerarchive ea
join vista.tikemployerarchive ea2 on (ea2.billnbr = ea.billnbr and ea2.kpvpartner <> ea.kpvpartner)
order by 1;
-- Divya 1 - not working:
select pvPartnerAddressDE.PKPVPARTID from vista.VPVPART_ADDR as pvPartnerAddressDE
inner join (select emp.kpvpartner from vista.tikemployerarchive as emp where emp.billnbr='100016') as vrole
on  pvPartnerAddressDE.PKPVPARTID =vrole.kpvpartner
and pvPartnerAddressDE.PVALIDFROM >=current date and pvPartnerAddressDE.PVALIDTO<=current date;
-- Divya 2 - working:
select pvPartnerAddressDE.PKPVPARTID, pvPartnerAddressDE.PVALIDFROM , pvPartnerAddressDE.PVALIDTO from vista.VPVPART_ADDR as pvPartnerAddressDE
inner join (select emp.kpvpartner from vista.tikemployerarchive as emp where emp.billnbr='100016') as vrole
on  pvPartnerAddressDE.PKPVPARTID =vrole.kpvpartner
and pvPartnerAddressDE.PVALIDFROM <=current date and pvPartnerAddressDE.PVALIDTO>=current date;
-- Divya 2 - other case - working:
select pvPartnerAddressDE.PKPVPARTID, pvPartnerAddressDE.PVALIDFROM , pvPartnerAddressDE.PVALIDTO from vista.VPVPART_ADDR as pvPartnerAddressDE
inner join (select emp.kpvpartner from vista.tikemployerarchive as emp where emp.billnbr='542308') as vrole
on  pvPartnerAddressDE.PKPVPARTID =vrole.kpvpartner
and pvPartnerAddressDE.PVALIDFROM <='1981-01-01' and pvPartnerAddressDE.PVALIDTO>='1981-01-01';
-- Divya 2 - improved:
select pvPartnerAddressDE.PKPVPARTID, pvPartnerAddressDE.PVALIDFROM , pvPartnerAddressDE.PVALIDTO from vista.VPVPART_ADDR as pvPartnerAddressDE
inner join (select emp.kpvpartner from vista.tikemployerarchive as emp where emp.billnbr='542308') as ea
on pvPartnerAddressDE.PKPVPARTID = ea.kpvpartner and pvPartnerAddressDE.PVALIDFROM <= '1981-01-01' and pvPartnerAddressDE.PVALIDTO >='1981-01-01';

select ea.tikearcid, ea.billnbr, ea.kpvpartner, ea. validfrom as ea_validfrom, ea.validto as ea_validto,
pvPartnerAddressDE.PKPVPARTID, pvPartnerAddressDE.PVALIDFROM, pvPartnerAddressDE.PVALIDTO
from vista.VPVPART_ADDR as pvPartnerAddressDE
inner join vista.tikemployerarchive ea
on pvPartnerAddressDE.PKPVPARTID = ea.kpvpartner
where ea.billnbr = '542308'
and pvPartnerAddressDE.PVALIDFROM <= '1981-01-01' and pvPartnerAddressDE.PVALIDTO >='1981-01-01';

-- Repli / GILAI
select * from vista.tpvdynamicparams;
select * from vista.aaireplication order by lastupdated desc;
select * from vista.aaipartner where taireplicationid=8023198296;
select * from vista.aaiaddress where taireplicationid=8023198296;

-- MQ Partner replication
select * from vista.tsfmqevent where lastupdated >= (current date - 0.5 days) order by lastupdated desc; -- key2 = 8023397541
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' and lastupdated >= (current date - 0.5 days) order by lastupdated desc;
select * from vista.tsfmqinbound where jmstype='BZ.PV-I003' and lastupdated >= (current date - 0.5 days) and inboundmsg like '%;8023397541;%' order by lastupdated desc;
select i.jmstype, i.jmsmessageid, i.jmscorrelationid, i.inboundmsg, i.lastupdated from vista.tsfmqinbound i 
where jmstype='BZ.PV-I003' and lastupdated >= (current date - 0.5 days) and inboundmsg like '%;8023397541;%' order by lastupdated desc; -- jmscorrelationid = '0d29186f-3771-4e1b-ab11-d20380d8f129'
select o.jmstype, o.jmsmessageid, o.jmscorrelationid, o.outboundmsg from vista.tsfmqoutbound o 
where jmstype='BZ.PV-I003' and lastupdated >= (current date - 0.5 days) and o.jmscorrelationid = '0d29186f-3771-4e1b-ab11-d20380d8f129';

-- 275704: Pool PV zugewiesen - Low - TI - prodTI: PV kpvpartid = 129945 ungültiger Nachname [#264172]
-- Liste
select distinct jp_new.kpvpartid, jp_new.personid as nnss, jp_new.tpvpartid as tpvpartid_new, jp_new.name as name_new,
jp_old.tpvpartid as tpvpartid_old, jp_old.name as name_old, jp_new.change_date as change_date_new
from vista.jpvpartner jp_new
join vista.jpvpartner jp_old on (jp_old.kpvpartid = jp_new.kpvpartid and jp_old.tpvpartid < jp_new.tpvpartid and jp_old.name <> jp_new.name)
where jp_new.kpvpartid < 1000000000 and jp_new.tpvpartid > 1000000000 and jp_new.change_user='MIGDBADM' and jp_old.change_user='MIGDBADM' and jp_new.operation = 'I' 
and jp_old.operation='U' and jp_new.validto='9999-12-31' and jp_old.validto='9999-12-31'; -- 17547
/*
KPVPARTID  NNSS           TPVPARTID_NEW  NAME_NEW                  TPVPARTID_OLD  NAME_OLD                CHANGE_DATE_NEW      
---------  -------------  -------------  ------------------------  -------------  ----------------------  -------------------  
71815      7563771877552  2017410278     Merlo                     71814          Merlo-Macconi           2021-03-12 08:28:41  
71839      7567257550045  2017410581     Masina                    71838          Masina Ferrari          2021-03-12 08:28:41  
71999      7565785408104  2018165316     Meier                     71998          Meier Peter             2021-03-12 08:29:57  
72519      7560177177156  2018165509     Mihajlovic                72517          Mihajlovic-Mitrovic     2021-03-12 08:29:57  
72837      7565213685008  2017412034     Bassi                     72836          Bassi-Rossi             2021-03-12 08:28:41  
72947      7561506412177  2018165883     Ott-Hess                  72940          Ott                     2021-03-12 08:29:57  
(...)
*/
-- Anzahl Partner (distinct kpvpartid):
select count(distinct jp_new.kpvpartid) as cnt_kpvpartid from vista.jpvpartner jp_new
join vista.jpvpartner jp_old on (jp_old.kpvpartid = jp_new.kpvpartid and jp_old.tpvpartid < jp_new.tpvpartid and jp_old.name <> jp_new.name)
where jp_new.kpvpartid < 1000000000 and jp_new.tpvpartid > 1000000000 and jp_new.change_user='MIGDBADM' and jp_old.change_user='MIGDBADM' and jp_new.operation = 'I' 
and jp_old.operation='U' and jp_new.validto='9999-12-31' and jp_old.validto='9999-12-31'; -- 17547



select distinct jp.kpvpartid, jp.personid as nnss, jp.tpvpartid as tpvpartid_new, jp.name as new_name, jp.program as program_new, 
jp2.tpvpartid as tpvpartid_old, jp2.name as old_name, jp2.program as program_old, jp.change_date 
from vista.jpvpartner jp
join vista.jpvpartner jp2 on (jp2.kpvpartid = jp.kpvpartid and jp2.tpvpartid < jp.tpvpartid and jp2.name <> jp.name)
where jp.kpvpartid > 1000000000 and jp.change_user='MIGDBADM' and jp2.change_user='MIGDBADM'
and jp.change_date >= jp2.change_date
 -- jp.operation = 'I' and jp2.operation='U' 
and jp.validto='9999-12-31' and jp2.validto='9999-12-31'; -- empty

select kpvpartid, tpvpartid, personid as nnss, name, program, change_user, operation, change_date 
from vista.jpvpartner jp 
where jp.kpvpartid < 1000000000 and jp.change_user='MIGDBADM' and operation in ('I', 'U');

select kpvpartid, tpvpartid, personid as nnss, name, program, change_user, operation, change_date 
from vista.jpvpartner jp 
where jp.kpvpartid > 1000000000 and kpvpartid=1000599902 and jp.change_user='MIGDBADM' and operation in ('I', 'U');

select count(distinct jp.kpvpartid) as cnt_j from vista.jpvpartner jp where jp.change_user='MIGDBADM'; -- 1'167'177

-- TPVEG
select * from vista.tpvpartner where clegaltype like '%#EG';
select * from vista.tpvheir;
select * from vista.tpvpartnergroup; -- empty
select * from vista.tpvgroupmember; -- empty
select * from vista.tpvexeccarrier order by lastupdated desc; -- role: 1433724598
select * from vista.tpvrole where tpvroleid=1433724598; -- Rolle#DFS
select * from vista.tpvparticipatorrel order by lastupdated desc;   -- role: 2663399507
select * from vista.tpvrole where kpvroleid=2663399507; -- 8808435
select * from vista.tpvpartner where kpvpartid=8808435;
-- REV
select * from vista.tpvrole where kpvpartid=5430468;
select * from vista.kpvrevisor; -- empty

-- Ticket

-- Case 1: 
select * from VISTA.TPVPARTNER where personid = '7565751677589';
-- TPVPARTID = 3006824849, KPVPARTID = 2341755, LEVAL Vanessa, CNAMESEQUENCE = NameHyphen#Y
select * from VISTA.TPVADDRESS where KPVPARTID = 2341755;

select * from vista.TPVADDRESSBASIC where KPVADBAID = 3001363899;

-- KEP-Handover:
-- CM / Config:
select c.code_id, c.shortcode, d.long_descript, attr.shortcode as attr_shortcode, attr.value as attr_value from vista.tiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=1)
left join vista.tiscmcodexcode x on (x.codeno = c.codeno)
left join vista.tiscmcode attr on (attr.codeno = x.code1)
where c.codetypeno in (select codetypeno from vista.tiscmcodetype where shortcode='KEPCONF')
order by c.value;
-- Sedex:
select * from vista.tzaxmlsdxrecord where lastupdated > current date - 5 days;
select * from vista.TZAXMLSDXRECORD
where date(lastupdated) >= current date - 5 days
and MESSAGETYPE in ('1118', '10099'); -- note: only 1118 used for KEP

select * from vista.TZAXMLSDXRECORD where MESSAGETYPE in ('1118', '10099') fetch first 10 rows only;
select * from vista.tpvkepprocessing;
select * from vista.tpvkeppartner where tpvkepprocid=7824409425;
select * from vista.tpvkeppb where tpvkepprocid=7824409425;
select ismainpartner, count(*) as cnt_p from vista.tpvkeppartner group by ismainpartner; -- 1699


select * from vista.tpvaddressbasic;

select * from vista.abdpostfilestreet;
select * from vista.abdpostfilezip;

select * from vista.tpvnotification order by lastupdated desc;
select ctargetappl, count(*) as cnt_app from vista.tpvnotification group by ctargetappl order by 2 desc;
/*
CTARGETAPPL    CNT_APP  
-------------  -------  
BusinessAp#IK  3174306  
BusinessAp#VB  2566892  
BusinessAp#IP  2412030  
BusinessAp#IV  71904    
BusinessAp#EL  31326    
BusinessAp#RE  2066     
BusinessAp#HE  123      
*/
select ctargetappl, count(*) as cnt_app from vista.tpvnotification where lastupdated > '2021-01-01' group by ctargetappl order by 2 desc;
/*
CTARGETAPPL    CNT_APP  
-------------  -------  
BusinessAp#RE  2066     
BusinessAp#HE  115      
*/
select count(*) as cnt_l from vista.tpvlog; -- 3723
select ctargetappl, count(*) as cnt_app from vista.tpvlog group by ctargetappl order by 2 desc;

-- NNP types
select * from vista.tpvpartner where clegaltype like '%#IVST';
select * from vista.tpvpartner where clegaltype like '%#KK';
select * from vista.tpvpartner where clegaltype like '%#POLG';

select * from vista.tpvelarpid;

-- 275676 - ZH - Gemeindefusion Zurzach
-- Neue Gde Edu ZH: 7879885180
select * from vista.tpvpartner where kpvpartid=7879885180; -- Gemeinde Zurzach, BFS: 4324
-- Neue Gde Prod ZH: 8078719027
select * from vista.tpvpartner where bfsmunitipalnr=4324; -- Gemeinde Zurzach, BFS: 4324
select * from vista.tpvpartner where kpvpartid in (3311899121, 3311899189, 3311899606, 3311899909, 3311899942, 3311899980, 3311900057, 3311900080);


WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where kpvpartid in (3311899121, 3311899189, 3311899606, 3311899909, 3311899942, 3311899980, 3311900057, 3311900080) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311899121, 3311899189, 3311899606, 3311899909, 3311899942, 3311899980, 3311900057, 3311900080) or 
    t.kpvpartid_taxdomicile in (3311899121, 3311899189, 3311899606, 3311899909, 3311899942, 3311899980, 3311900057, 3311900080) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid; -- Edu: ??, danach 0;;;  prodZH: 1589. danach: 2: 7561589585737 und 7563036325859

-- Stichproben:
select a.kpvpartid, p.personid as nnss, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.validfrom, a.validto, a.lastupdated, a.kpvpartid_munauthor, polg.name, polg.bfsmunitipalnr
from vista.tpvaddress a left join vista.tpvpartner polg on (polg.kpvpartid = a.kpvpartid_munauthor and polg.validto >= current date)
left join vista.tpvpartner p on (p.kpvpartid = a.kpvpartid and p.validto >= current date) where a.kpvadrsid=30108609;

-- PV-WP-04
select * from vista.tpvpartner where kpvpartid=2174868; -- CorresLang#D
-- AIT, nicolas fournier
select * from vista.tpvpartner where kpvpartid=30005;
update vista.tpvpartner set clanguage='CorresLang#D', lastupdated = current timestamp where kpvpartid=30005;
-- Fournier, Anna (167913487)
select * from vista.tpvpartner where kpvpartid=167913487;
select * from vista.tpvelarpid where kpvpartid=167913487; -- empty!
-- Müller Barbara (1105916)
select * from vista.tpvpartner where kpvpartid=1105916;
select * from vista.tpvelarpid where kpvpartid=1105916; -- V1105916
update vista.tpvpartner set clanguage='CorresLang#F', lastupdated = current timestamp where kpvpartid=1105916;

-- 276661 - TI - Anrede auf RoleRel
select * from vista.tpvpartner where personid='7567473982729'; -- 1000800351
select * from vista.tpvrole where kpvpartid=1000800351; -- STA: 2032600564, EL: 3198945990
select * from vista.tpvrolerel where kpvroleid_source in (2032600564, 3198945990) or kpvroleid_target in (2032600564, 3198945990);
select * from vista.jpvrolerel where kpvrrelid=3277257698; -- Insert: EL:APP129_EL-Dlg-114_Decrees_e, Update: PV:PV-Dlg-704 Dialog Periode Korrespondenzempfaenger


select * from vista.TPVPARTNER p
join vista.TPVADDRESS adr on adr.KPVPARTID = p.KPVPARTID
join vista.TPVROLEREL rel ON rel.KPVADRSID_CORR IN (1001519349,1002523826)
where p.PERSONID = '7567473982729';


select c.code_id, c.shortcode, c.const_field, c.value, c.change_user, c.program, c.operation, c.change_date, d.medium_descript from vista.jiscmcode c 
left join vista.tiscmcode_descr d on (d.codetypeno = c.codetypeno and d.codeno = c.codeno and d.language=4)
where c.code_id like 'PVCONST#PVCONST_59'
order by c.shortcode;

select * from vista.abdpostfilestreet where polgcanton = 'SG' order by zip6, street, streetnr;
select * from vista.abdpostfilezip where canton = 'SG' order by zip6; -- 731060
select * from vista.abdpostfilestreet where zip6 = '731060';

select * from vista.tpvaddressbasic;
select * from vista.tpvaddress where cbusinessapp is not null;
select cbusinessapp, count(*) as cnt_app from vista.tpvaddress where cbusinessapp is not null group by cbusinessapp; -- BusinessAp#IP

select p.name, a.* from vista.tpvpartner p join vista.tpvalias a on (a.kpvpartid = p.kpvpartid) where a.aliasterm is not null;
select * from vista.tpvfamilyrel;

select * from vista.tpveducation where lastupdated > '2018-01-01';
select * from vista.tpvtaxdata where lastupdated > '2020-01-01';
select * from vista.jpvtaxdata where change_date > '2020-01-01';

select count(distinct kpvtaxdid) from vista.tpvtaxdata; -- ZH: 1382898, GE: 0, SG: 502283, SZ: 121564, UR: 12
select cpaytype, count(*) as cnt_pa from vista.tpvpaymentaddr where validto > current date group by cpaytype order by 2 desc;
select * from vista.tpvpaymentaddr where ccountry is not null and validto > current date;


-- KEP: Postkörbe - Analyse ----------------------
-- 28.03.2022

-- Wie viele PBs pro Typ? (NULL = kein PB ausgelöst)
select pbtype, count(*) as cnt_pb from vista.tpvkeppb group by pbtype order by 2 desc;
/*
PBTYPE  CNT_PB  
------  ------  
(null)  28879   
KPAD    23174   
KPSP    9636    
KPFR    6225    
KPGT    3911    
KPTD    164     
*/
-- Gibt es "Ausreisser" (Massenhaft PKs pro Tag)?
select date(lastupdated) as day_kpad, count(*) as cnt_kpad from vista.tpvkeppb where pbtype='KPAD' group by date(lastupdated) order by 2 desc;
/*
DAY_KPAD    CNT_KPAD  
----------  --------  
2022-01-05  1235      
2022-03-01  916       
2022-01-11  780       
2022-02-01  661       
2022-03-14  652       
2022-01-26  642       
2022-01-28  635       
2022-02-24  598       
2022-02-07  594       
2022-03-22  572       
2022-02-28  571       
(...)
*/
-- Wie viele PBs total?
-- Hinweis: Nur Daten für 3 Monate zurück (Clean-Up-Job löscht alte Einträge!)
select count(*) from vista.tpvkeppb pb where pb.pbtype is not null and date(pb.lastupdated) between '2022-01-01' and '2022-03-27'; -- Total PBs: 42'107 (in ca. 3 Monaten)
-- Davon KPADs?
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27'; -- 22'842 (54%)
-- Davon pro Monat?
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-01-31'; -- 8'022
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-02-01' and '2022-02-28'; -- 8'015
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-03-01' and '2022-03-28'; -- 6'805 (allerdings Monat noch nicht ganz fertig... )

-- Fallen EL-Fälle ins Gewicht? (dürften nicht automatisch mutiert werden) --> nein:
select count(pb.tpvkeppbid) from vista.tpvkeppb pb join vista.tpvrole r on (r.kpvpartid = pb.kpvpartid and r.croletype = 'Rolle#EL') 
where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-28'; -- 210 --> nur ca. 1% aller KPADs betreffen einen EL-Fall --> Fällt kaum ins Gewicht...

-- Zuzugsdatum:
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and karrivaldate is not null; -- 22'842 --> ArrivalDate wird immer gesetzt!
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and karrivaldate is null; -- 0 (siehe oben)
-- Umzugsdatum:
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate is not null; -- 10'240 --> ca. 50% aller KPADs
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate > karrivaldate; -- 10'240 --> also immer!
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate < karrivaldate; -- 0 (siehe oben)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate > karrivaldate; -- 10'240 --> also immer!
-- Berücksichtigung "16 Monate":
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate > (date('2022-03-28') - 480 days) ; -- 8'438 (Umzugsdatum jünger als 16 Monate)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate < (date('2022-03-28') - 480 days) ; -- 1'802 (Umzugsdatum älter als 16 Monate)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate is null and karrivaldate < (date('2022-03-28') - 480 days) ; -- 3'861 (Ankunftsdatum jünger als 16 Mte.)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days) ; -- 8'740 (Ankunftsdatum älter als 16 Mte.)
-- veraltete Meldungen ganz ignorieren (weder Mutation noch PK):
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate < (date('2022-03-28') - 480 days)) or kmovingdate < (date('2022-03-28') - 480 days)) ; -- 5'663 "veraltete" Meldungen (25% aller KPADs, bzw. 13 % aller PKs)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) ; -- 17'178 "aktuelle" Meldungen (75% aller KPADs, bzw. 37 % aller PKs)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) and
kaddressline1 is null and kaddressline2 is null; -- 15'772 "aktuelle" Meldungen OHNE Adresszusatz (69% aller KPADs)
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) and
kaddressline1 is null and kaddressline2 is null
and dstreet = 0; -- 2'193 "aktuelle" Meldungen OHNE Adresszusatz und gleicher Strasse
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) and
kaddressline1 is null and kaddressline2 is null
and dstreet = 0 and (dewid = 1 or degid = 1); -- 2'161 "aktuelle" Meldungen OHNE Adresszusatz und gleicher Strasse, nur EWID / EGID unterschiedlich --> Automat. Setzen von EWID / EGID
select count(*) from vista.tpvkeppb pb where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) and
kaddressline1 is null and kaddressline2 is null
and vstreet is null; -- 2'090 "aktuelle" Meldungen OHNE Adresszusatz, keine Adresse in VISTA --> Kandidaten für automat. neue Adresse erstellen.

-- Abschätzung KEP-Meldung neuer als VISTA:
-- Zunächst: unterschiedliche Strasse gemeldet, aktuelle Periode hat (mittlerweile) das gleiche Datum wie Zuzug/Umzug (war zum Zeitpunkt des PKs ev. nicht so!)
select count(*) from vista.tpvkeppb pb 
left join vista.tpvaddress a on (a.kpvpartid = pb.kpvpartid and a.caddresstype='AddressTyp#WS' and a.validto='9999-12-31')
where pb.pbtype='KPAD' and date(pb.lastupdated) between '2022-01-01' and '2022-03-27' and 
( (kmovingdate is null and karrivaldate > (date('2022-03-28') - 480 days)) or kmovingdate > (date('2022-03-28') - 480 days)) and
kaddressline1 is null and kaddressline2 is null
and dstreet = 1 and 
(a.validfrom = kmovingdate or a.validfrom = karrivaldate); -- 7'295
-- (...)

-- ECM - LZPVRR003 Test 08.04.2022 - mandatory parameter?
select * from vista.tikemployerarchive where billnbr='427195'; -- kpvpartner: 9000010001200004
select * from vista.tpvpartner where kpvpartid=9000010001200004;
select * from vista.tpvelarpid where kpvpartid=9000010001200004; -- V9000010001200004 
select * from vista.tsfmqoutbound o where o.lastupdated > '2022-01-31' and reason is not null order by o.lastupdated desc; -- MQOUTBREJ#INVOUTXML

select * from vista.tsfmqinbound i where i.lastupdated >= (current date - 0.5 day) and i.jmstype='LZ.PV-RR003' order by i.lastupdated desc;
select * from vista.tsfmqoutbound o where o.lastupdated >= (current date - 0.5 day) and o.jmstype='LZ.PV-RR003' order by o.lastupdated desc;
-- old entries
select * from vista.tsfmqinbound i where i.jmstype='LZ.PV-RR003' order by i.lastupdated desc;
select * from vista.tsfmqoutbound o where o.jmstype='LZ.PV-RR003' order by o.lastupdated desc;
select * from vista.tsfmqoutbound o where o.jmstype='LZ.PV-RR003' and o.outboundmsg like '%billingNumber%' order by o.lastupdated desc;

-- Protection Code in IK:
select * from vista.tikheader order by lastupdated desc;
select * from vista.tikowner order by lastupdated desc;

-- LZ.PV-N001 - Contact Center Notification:
select * from vista.tsfmqoutbound o where o.jmstype='LZ.PV-N001' order by o.lastupdated desc;
select o.reason, count(*) as cnt_reason from vista.tsfmqoutbound o where o.jmstype='LZ.PV-N001' group by o.reason order by 2 desc;
/*
REASON                CNT_REASON  
--------------------  ----------  
(null)                713629      
MQOUTINFO#IGNOREREPL  5923        
MQOUTBREJ#BEANERROR   521         
MQOUTBREJ#INVOUTXML   225         
MQOUTBREJ#UNTECHERR   47          
*/

-- Report:
with q as (
    select distinct o.reason, o.jmscorrelationid,
    cast(i.inboundmsg as varchar(100)) as inboundmsg, -- cast is required to use distinct on a CLOB...
    cast(
        replace(
            substring(i.inboundmsg, locate_in_string (left(i.inboundmsg, length(i.inboundmsg)-1 ), ';', -1))
        , ';', '')
        as varchar(21)
    ) as kpv_mq, -- extracts the logical key of the replicated item, out of a string like: 'PARTNER;U;4583509726;135165453;' --> (4th element)
    o.lastupdated as lastupdated_out from vista.tsfmqoutbound o
    left join vista.tsfmqinbound i on (i.jmscorrelationid = o.jmscorrelationid)
    where o.jmstype='BZ.PV-I003' -- or LZ.PV-N001...
    and o.reason='MQOUTBREJ#BEANERROR' -- or INVOUTXML, IGNOREREPL, ...
    and i.lastupdated >= '2022-04-14' ---- or your due date...
), err as (
    select q.*, 
    case when q.inboundmsg like 'PARTNER%' then q.kpv_mq 
         when q.inboundmsg like 'ADDRESS%' then (select max(kpvpartid) from vista.tpvaddress a where a.kpvadrsid = q.kpv_mq)
         when q.inboundmsg like 'PAYMENTADDR%' then (select kpvpartid from vista.tpvpaymentaddr pa where pa.kpvpaddid = q.kpv_mq fetch first 1 row only)
         when q.inboundmsg like 'ROLE%' then (select max(kpvpartid) from vista.tpvrole r where r.kpvroleid = q.kpv_mq)
         -- when q.inboundmsg like 'FAMILYREL%' then (select max(kpvpartid_source) from vista.tpvfamilyrel fr where fr.tpvfrelid = q.kpv_mq) 
         -- simplification: only source partner -- does not work, as there is no 4th element: FAMILYREL;I;8437250417;;
         else -1 -- could be extended with ADDRESSBASIC, TAXDATA, ...
    end as kpvpartid_mq
    from q
), partner as (
    select err.*,
    p.kpvpartid, p.tpvpartid, p.cpartnertype, p.personid, p.clegaltype, p.clegalform, p.ccitizenship, p.validfrom, p.validto -- any other attributes if required
    from err
    left join vista.tpvpartner p on (p.kpvpartid = cast(err.kpvpartid_mq as bigint))
), overview as (
    select partner.reason, partner.jmscorrelationid, partner.inboundmsg, partner.kpv_mq, partner.kpvpartid, partner.tpvpartid, partner.cpartnertype, partner.personid, 
    partner.clegaltype, partner.clegalform, partner.ccitizenship, partner.validfrom, partner.validto,
    a.kpvadrsid, a.caddresstype, ab.zip, ab.city, ab.ccountry, ab.validfrom as ab_validrom, ab.validto as ab_validto -- any other attributes / joines if required
    from partner 
    left join vista.tpvaddress a on (a.kpvpartid = partner.kpvpartid)
    left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid)
    order by partner.kpvpartid desc, partner.tpvpartid desc
)
--select distinct * from err;
select distinct * from overview
--left join vista.tpvrole r on (r.kpvpartid = overview.kpvpartid);
left join vista.tpvrole r on (r.kpvpartid = overview.kpvpartid);

select * from vista.tpvemployee;

select * from vista.tsfmqoutbound o where o.jmstype='LZ.PV-N001' and reason is not null order by o.lastupdated desc;
select * from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' and reason is not null order by o.lastupdated desc;
select * from vista.tsfmqoutbound o where o.jmstype='BZ.PV-I003' and reason='MQOUTBREJ#BEANERROR' order by o.lastupdated desc;
-- c4111ea7-b425-45d0-9556-4abab9520511: kpvpartid = "381494685"
select * from vista.tpvpartner where kpvpartid=381494685;
select * from vista.tpvrole where kpvpartid=381494685;


-- Notification
select * from vista.tpvlog;
select * from vista.tpvnotification order by lastupdated desc;

-- Partner Types

-- 281066 - ZH - Gemeindefusion Böztal:
select * from vista.tpvpartner where name='Gemeinde Böztal'; -- 7943637580 / BFS: 4185 --> prod: 8477899709
WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (-1, 4185) or ahvbranchnr in (-1, -2)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) or kpvpartid in (3311900571, 3311900619, 3311900640, 98680961) order by kpvpartid, bfsmunitipalnr;
--
select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (3311900571, 3311900619, 3311900640, 98680961) or 
    t.kpvpartid_taxdomicile in (3311900571, 3311900619, 3311900640, 98680961) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;

-- KEP
select * from vista.tpvkeppb;
select * from vista.tpvaddress;
select * from vista.tpvpartner where kpvpartid=9000030000001923;

-- Defect 110305 - PV.2022.108229_Adressen:Hausnummer ohne Strassennamen verhindern_A6
select * from vista.tpvaddressbasic where street is null;
select * from vista.tpvaddress order by lastupdated desc; -- 7236609
update vista.tpvaddress set streetnr='99', lastupdated=current timestamp where kpvadrsid=7236609;
update vista.tpvaddress set validto='9999-12-31', validfrom='2010-01-01', lastupdated=current timestamp where kpvadrsid=7236609;
-- getestet auf SIT417 mit SR58.001
select * from vista.tpvaddressbasic order by lastupdated desc; -- 7236609
select * from vista.tpvpartner where kpvpartid=5123642;
select * from vista.tpvaddress where kpvpartid=5123642; -- 956834 (WS)
select * from vista.tpvaddressbasic where kpvadbaid=396565;
select * from vista.tpvaddressbasic where street is null and ccountry='Country#CH';
select count(*) from vista.tpvaddressbasic where street is null and ccountry='Country#CH';

-- IK:null
select distinct program from vista.jpvpartner where program like '%null%'; -- IK:null
select program, count(*) as cnt_p from vista.jpvpartner where program like '%null%' group by program;
/*
PROGRAM  CNT_P  
-------  -----  
IK:null  5744   
*/
select program, count(*) as cnt_p from vista.jpvrole where program like '%null%' group by program;
/*
PROGRAM  CNT_P  
-------  -----  
EL:null  8924   
HE:null  702    
IK:null  71986  
PV:null  8849   
VB:null  70010  
*/
select distinct program from vista.jpvaddress where program like '%null%'; -- empty
select program, count(*) as cnt_p from vista.jikheader where program like '%null%' group by program;
/*
PROGRAM  CNT_P  
-------  -----  
IK:null  81428  
*/
select program, count(*) as cnt_p from vista.jikvaikrequest where program like '%null%' group by program; -- empty


-- 285399 - ZH - KEP work unit Errors
select s.tzaxmlsdxrecordid, s.messagetype, s.state, s.lastupdated from vista.tzaxmlsdxrecord s where s.messagetype=1118 and state=2 
order by lastupdated desc fetch first 20 rows only;
/*
TZAXMLSDXRECORDID  MESSAGETYPE  STATE  LASTUPDATED          
-----------------  -----------  -----  -------------------  
8586293121         1118         2      2022-05-09 21:35:33  
7803601939         1118         2      2022-01-04 21:40:03  
7680189465         1118         2      2021-12-14 21:49:07  
7589221435         1118         2      2021-11-30 21:35:39  
7564224906         1118         2      2021-11-29 21:34:18  
7420603665         1118         2      2021-11-09 21:34:14  
7315917570         1118         2      2021-10-29 21:34:05  
7269934204         1118         2      2021-10-22 21:35:43  
7233527468         1118         2      2021-10-15 21:40:20  
7164590532         1118         2      2021-10-04 21:34:16  
6884349438         1118         2      2021-08-18 21:33:01  
6785533941         1118         2      2021-07-30 21:32:57  
*/
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=8586293121; -- 830
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7164590532; -- 997
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7315917570; -- 1077
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7564224906; -- 680
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7589221435; -- 2021
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7803601939; -- 5503
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=6785533941; -- 370
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=6884349438; -- 241
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7233527468; -- 5751
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7269934204; -- 1017
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7420603665; -- 1022
select s.recorddata from vista.tzaxmlsdxrecord s where s.tzaxmlsdxrecordid=7680189465; -- 14833 @ 38 sec (memory problem mit DBVisualizer)

select * from vista.tpvrole;

SELECT * FROM vista.tpvaddressbasic where street like '%é%';
select * from vista.tpvaddressbasic where upperstreet like '%Í%';


-- 284088 - Gemeindefusion - TI - Val Mara
select * from vista.tpvpartner p where p.name='Val Mara' or p.bfsmunitipalnr='5240'; -- edu: nicht vorhanden
select * from vista.tpvpartner p where p.name='Val Mara' or p.bfsmunitipalnr='5195' or kpvpartid=71287; -- prod: kpvpartid = 71410


-- 284419 - AI - Gemeindefusion - Schwende-Rüte
select * from vista.tpvpartner p where p.bfsmunitipalnr='3112'; -- edu: 368893155
select * from vista.tpvpartner p where p.bfsmunitipalnr='3112'; -- prod: 370133874

WITH x AS (
    select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
    from vista.tpvpartner where (bfsmunitipalnr in (3105, 3103, 3112) or ahvbranchnr in (-1, -2)) and clegaltype='NNPersonTy#POLG'
)
select tpvpartid, kpvpartid, kpvpartid_ahvbranchnr, name, additionalname, clegaltype, munauthornr, ahvbranchnr, cmunauthorflg, bfsmunitipalnr, validfrom, validto, lastupdated 
from vista.tpvpartner where kpvpartid in ( select x.kpvpartid from x) order by kpvpartid, bfsmunitipalnr;

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.socialsecnr, p.personid, 
p.validfrom, p.validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address,
a.validfrom, a.validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata,
t.validfrom, t.validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (209053887, 209054429) or 
    t.kpvpartid_taxdomicile in (209053887, 209054429) 
)
and p.cpartnertype='PartnerTyp#NP' and p.validto = '9999-12-31'
order by p.kpvpartid;

select p.kpvpartid, p.tpvpartid, p.name, p.firstname, p.birthdate, p.personid, 
p.validfrom as p_validfrom, p.validto as p_validto, a.kpvadrsid, a.tpvadrsid, a.caddresstype, a.kpvpartid_munauthor,
(select max(p2.bfsmunitipalnr) from vista.tpvpartner p2 where p2.kpvpartid = a.kpvpartid_munauthor) as bfs_no_address, -- to be improved, use data from latest period
a.validfrom as a_validfrom, a.validto as a_validto, t.kpvtaxdid, t.tpvtaxdid, t.kpvpartid_taxdomicile, 
(select max(p3.bfsmunitipalnr) from vista.tpvpartner p3 where p3.kpvpartid = t.kpvpartid_taxdomicile) as bfs_no_taxdata, -- to be improved, use data from latest period
t.validfrom as t_validfrom, t.validto as t_validto
from vista.tpvpartner p
left join vista.tpvaddress a on (a.kpvpartid = p.kpvpartid and a.validto = '9999-12-31' and a.caddresstype in ('AddressTyp#WS', 'AddressTyp#GS') )
left join vista.tpvtaxdata t on (t.kpvpartid = p.kpvpartid and t.validto = '9999-12-31')
where (
    a.kpvpartid_munauthor in (209053887, 209054429) or -- old POLGs
    t.kpvpartid_taxdomicile in (209053887, 209054429) -- old POLGs
)
and p.cpartnertype='PartnerTyp#NP' -- possibly also for NNP?
and p.validto = '9999-12-31'
order by p.kpvpartid;

-- Gemeindefusionen
select * from vista.abdpostfilestreet; -- 2022-04-06 16:14:48
select max(lastupdated) from vista.abdpostfilestreet; -- 2022-04-06 16:14:48
select ab.zip, ab.street, a.* from vista.tpvaddress a left join vista.tpvaddressbasic ab on (ab.kpvadbaid = a.kpvadbaid) where ab.street='Kreuzhofstrasse' and a.streetnr='11'; -- POLG = 209053887
select * from vista.tpvpartner where kpvpartid=209053887; -- BFS = 3103
select * from vista.abdpostfilestreet p where p.street='Kreuzhofstrasse';

-- KEP - PVJKEPI error
select s.tzaxmlsdxrecordid, s.messagetype, s.state, s.lastupdated from vista.tzaxmlsdxrecord s where s.messagetype=1118 and state=2 
order by lastupdated desc fetch first 20 rows only;

-- Fusioned POLGs:
select * from vista.tpvpartner where clegaltype='NNPersonTy#POLG';

