/*<OXADWDB>*/
<SEPARATEUR>
/*Reglements*/
if exists (select * from <PREFIXE_DW>sysobjects where name='FACTURES_REGLEMENTS' and xtype='U') drop table  <PREFIXE_DW>FACTURES_REGLEMENTS

<SEPARATEUR>
/*Reglements*/
select soc.CODE_STE as REG_CODE_SOCIETE,
soc.RAIS_SOC as REG_RAISON_SOCIALE_SOCIETE,
reg.NUM_FAC as REG_NUMERO_FACTURE,
fac.CODE_FOUR as REG_CODE_FOURNISSEUR,
frs.RS as REG_RAISON_SOCIALE_FOURNISSEUR,
fac.FACT_FOU as REG_NUMERO_FACTURE_FOURNISSEUR,
reg.NUM_REG as REG_NUMERO_REGLEMENT,
reg.REF_REG as REG_REFERENCE_REGLEMENT,
reg.DTE_REG as REG_DATE_REGLEMENT,
reg.MODE_REG as REG_MODE_REGLEMENT,
mod.LIBELLE as REG_LIBELLE_REGLEMENT,
reg.MT_REG as REG_MONTANT_REGLEMENT,
reg.MT_REG_DEV as REG_MONTANT_DEVISE_REGLEMENT,
reg.DEVISE as REG_DEVISE_REGLEMENT,
reg.TYP_MT as REG_TYPE_REGLEMENT,
memo.CONTMEMO  as REG_COMMENTAIRE
into <PREFIXE_DW>FACTURES_REGLEMENTS
from <PREFIXE_HA>FAC_REG reg with(nolock)
left outer join <PREFIXE_HA>FAC_ENT fac with(nolock) on reg.NUM_FAC=fac.NUM_FACT
left outer join <PREFIXE_HA>SOCIETE soc with(nolock) on fac.CODE_STE=soc.CODE_STE
left outer join <PREFIXE_HA>FOURNISS frs with(nolock) on fac.CODE_FOUR=frs.CODE
left outer join <PREFIXE_HA>MODEPAIE mod with(nolock) on fac.MODE_REG=mod.CODE_MDP
left outer join <PREFIXE_HA>MEMOS memo with(nolock) on reg.NM_COMMENT=memo.NODEMEMO