TRUNCATE TABLE <PREFIXE_DW>CODES_GESTION

insert  into <PREFIXE_DW>CODES_GESTION (CG_CODE_SOCIETE,CG_CODE_GESTION_INTERNE,CG_CODE_GESTION_AFFICHE,CG_CODE_SECTION_IMPUTATION,CG_LIBELLE_CODE_GESTION,CG_NUMERO_LOT,CG_ID_PARENT,CG_DATE_MIN,CG_DATE_MAX,CG_AUTORISE_ACHAT)
select CODE_STE,CODE_GES,CODE_AFF,CODE_SI,LIB_GES,NUM_LOT,ID_PARENT,CASE WHEN (DTEVALMIN = ' ' OR DTEVALMIN = '00000000' ) THEN CONVERT (datetime,'19000101' ,103) WHEN (DTEVALMIN < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,DTEVALMIN ,103) END,CASE WHEN (DTEVALMAX = ' ' OR DTEVALMAX = '00000000' ) THEN CONVERT (datetime,'19000101' ,103) WHEN (DTEVALMAX < '17530101') THEN CONVERT (datetime,'19000101' ,103) ELSE CONVERT (datetime,DTEVALMAX ,103) END,CASE WHEN (AUTHACHAT =0x54) then 1 else 0 end 
from <PREFIXE_HA>CODGEST  <WITHNOLOCK>

/*============RECHERCHE LIB SOCIETE*/
update cg set CG_LIBELLE_SOCIETE=RAIS_SOC from <PREFIXE_DW>CODES_GESTION cg , <PREFIXE_HA>SOCIETE d <WITHNOLOCK> where cg.CG_CODE_SOCIETE=d.CODE_STE

/*============RECHERCHE LIB SI*/
update cg set CG_LIBELLE_SECTION_IMPUTATION=LIBELLE,CG_CODE_DIRECTION=CODE_DIR from <PREFIXE_DW>CODES_GESTION cg , <PREFIXE_HA>SECTIMPU d <WITHNOLOCK> where cg.CG_CODE_SOCIETE=d.CODE_STE and cg.CG_CODE_SECTION_IMPUTATION=CODE_SI

/*============RECHERCHE LIB DIR */
update cg set CG_LIBELLE_DIRECTION=LIBELLE from <PREFIXE_DW>CODES_GESTION cg , <PREFIXE_HA>DIRECTIO d <WITHNOLOCK> where cg.CG_CODE_SOCIETE=d.CODE_STE and cg.CG_CODE_DIRECTION=CODE_DIR

