/*Correct bad dates in AO_PLANN*/
update pla set DTE = ent.DTE_AO from <PREFIXE_HA>AO_PLANN pla join <PREFIXE_HA>AO_ENTET ent  with (nolock)  on pla.NO_AO = ent.NO_AO where ISDATE(pla.DTE)=0 and cast(pla.NO_AO as varchar)+ ent.DTE_AO not in (select cast(l.NO_AO as varchar)+ e.DTE_AO from <PREFIXE_HA>AO_PLANN l left outer join <PREFIXE_HA>AO_ENTET e on e.NO_AO=l.NO_AO where ISDATE(l.DTE)=1 )
<SEPARATEUR>
/*Ajout Champ FOURNISS.MODIFPAR si existe pas*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='FOURNISS' and COLUMN_NAME='MODIFPAR') alter table <PREFIXE_HA>FOURNISS add MODIFPAR varchar(30) not null default ' '
<SEPARATEUR>
/*Ajout Champ FOURNISS.ENSCOMM si existe pas*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='FOURNISS' and COLUMN_NAME='ENSCOMM') alter table <PREFIXE_HA>FOURNISS add ENSCOMM varchar(100) not null default ' '
<SEPARATEUR>
/*Ajout Champ FAC_ENT.LIB_COMPT si existe pas*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='FAC_ENT' and COLUMN_NAME='LIB_COMPT') alter table <PREFIXE_HA>FAC_ENT add LIB_COMPT varchar(30) not null default ' '

<SEPARATEUR>
/*Ajout Champ FAC_ENT.ACOMPTE si existe pas spec 5176*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='FAC_ENT' and COLUMN_NAME='ACOMPTE')   alter table <PREFIXE_HA>FAC_ENT add ACOMPTE binary not null default 0x46

<SEPARATEUR>
/*Ajout Champ BDD_OBJECTS.BDD_DESCRIPTION si existe pas*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='BDD_OBJECTS' and COLUMN_NAME='BDD_DESCRIPTION') alter table <PREFIXE_HA>BDD_OBJECTS add BDD_DESCRIPTION varchar(1000) not null default ' '
<SEPARATEUR>
/*MAJ evt imp si manquant, attention il faut mettre le nom de la base devant la table*/
update <PREFIXE_HA>CA_ENTET
set EVE_IMP=isnull((select top 1 NUM_ORD from <PREFIXE_HA>CA_EVENT eve
where eve.NO_CDE=CA_ENTET.NO_CDE and eve.AVNT=CA_ENTET.AVENANT and (eve.CODE=N'IMP' or eve.CODE=N'MEL' or eve.CODE=N'FAX') order by eve.NUM_ORD desc),0)
where SIGNEE=0x54 and (ETAT_CDE=N'E' or ETAT_CDE=N'S') and EVE_IMP=0
<SEPARATEUR>
/*ajout col AO_REP.PAY_PROV 10.32ah*/
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='AO_REP' and COLUMN_NAME='PAY_ORI') alter table <PREFIXE_HA>AO_REP add PAY_ORI varchar(25) not null default ' '
if not exists (SELECT * FROM <PREFIXE_HABDD>INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME='AO_REP' and COLUMN_NAME='PAY_PROV') alter table <PREFIXE_HA>AO_REP add PAY_PROV varchar(25) not null default ' '
<SEPARATEUR>
/*Correction BR_RECEP.DATE_CRE validated by YA/RA 03/2025*/
update b set b.DATE_CRE=e.DATE_CRE
from <PREFIXE_HA>BR_RECEP b, <PREFIXE_HA>BR_EVENT e where b.NUM_BR = e.NUM_BR and CODE_EVE='CRE' and isdate(b.DATE_CRE)=0

<SEPARATEUR>
/*Correction FAC_ENT.DTE_DERNREG validated by RA 08/2025*/
update <PREFIXE_HA>FAC_ENT set DTE_DERNREG='00000000' where isdate(DTE_DERNREG)=0 and DTE_DERNREG<>'00000000' and DTE_DERNREG<>''