<efact_custom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<row>
  <codefactc>1</codefactc>
  <den_efcustom>METRO</den_efcustom>
  <sqlcampuri>select
      nas.GLN as BT_29,  -- GLN  vanzator
      '0209' as BT_29_1,  -- identificator schema GLN  vanzator
      napartsoc.GLN as BT_46, -- GLN sediu social cumparator,
      '0209' as BT_46_1, -- identificator schema GLN sediu social cumparator,
      np.den_part||'-'||napartlivr.obs  as BT_70 -- nume partener + numele sediului de livrare
from iesiri ies
inner join npart np on np.codpart=ies.partener
inner join nsubunit nsub on ies.subunitatea=nsub.codsubunit
left join nagenda nas on nas.codsubunit=nsub.codsubunit
left join nagenda napartsoc on napartsoc.codpart= np.codpart and napartsoc.SEDIUSOCIAL in (4,5,6,7) and coalesce(napartsoc.inactiv,0)=0
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
where ies.codies = &lt;WM_CODDOC&gt;</sqlcampuri>
</row>

<row>
  <codefactc>6</codefactc>
  <den_efcustom>SELGROS</den_efcustom>
  <sqlcampuri>select
      nas.GLN as BT_29,  -- GLN  vanzator
      '0209' as BT_29_1,  -- identificator schema GLN  vanzator
      --iesext.extensie as BT_10, -- extensie la nivel de factura, unde se poate introduce codul de furnizor atribuit de Selgros
       napartsoc.GLN as BT_46, -- GLN sediu social cumparator,
      '0209' as BT_46_1, -- identificator schema GLN sediu social cumparator,
      np.den_part||'-'||napartlivr.obs  as BT_70 -- nume partener + numele sediului de livrare

from iesiri ies
inner join npart np on np.codpart=ies.partener
inner join nsubunit nsub on ies.subunitatea=nsub.codsubunit
left join nagenda nas on nas.codsubunit=nsub.codsubunit
left join nagenda napartsoc on napartsoc.codpart= np.codpart and napartsoc.SEDIUSOCIAL in (4,5,6,7) and coalesce(napartsoc.inactiv,0)=0
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
left join iesiriext iesext on iesext.codies=ies.codies
where ies.codies = &lt;WM_CODDOC&gt;</sqlcampuri>
</row>

<row>
  <codefactc>4</codefactc>
  <den_efcustom>PENNY</den_efcustom>
  <sqlcampuri>select
      nas.GLN as BT_29,  -- GLN  vanzator
      '0209' as BT_29_1,  -- identificator schema GLN  vanzator
      napartsoc.GLN as BT_46, -- GLN sediu social cumparator,
      '0209' as BT_46_1, -- identificator schema GLN sediu social cumparator,
      np.den_part||'-'||np.obs  as BT_70, -- numele partii catre care se face livrarea - magazin sau   depozit
      Case when (Select Count(*) CateStocuri from IESIRI1 I1 WHERE I1.CodIes = &lt;WM_CodDoc&gt; and I1.TIPLINIE = '=') = 0 then '2' else '1' end  As BT_23 -- Business Process Type
from iesiri ies
inner join iesiri1 ie1 on ie1.codies=ies.codies
inner join npart np on np.codpart=ies.partener
inner join nsubunit nsub on ies.subunitatea=nsub.codsubunit
left join nagenda nas on nas.codsubunit=nsub.codsubunit
left join nagenda napartsoc on napartsoc.codpart= np.codpart and napartsoc.SEDIUSOCIAL in (4,5,6,7) and coalesce(napartsoc.inactiv,0)=0
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
where ies.codies = &lt;WM_CodDoc&gt;</sqlcampuri>
</row>

<row>
  <codefactc>5</codefactc>
  <den_efcustom>KAUFLAND</den_efcustom>
  <sqlcampuri>select
      nas.GLN as BT_29,  --GLN  vanzator
      '0088' as BT_29_1,  -- identificator schema GLN  vanzator
      '4049728000004' as BT_46, -- GLN sediu social cumparator,
      '0088' as BT_46_1, -- identificator schema GLN sediu social cumparator,
      np.den_part||'-'||napartlivr.obs  as BT_70, -- nume partener + numele sediului de livrare
      napartlivr.GLN as BT_71, -- GLN sediu livrare cumparator,
      '0088' as BT_71_1 -- GLN sediu livrare cumparator
from iesiri ies
inner join npart np on np.codpart=ies.partener
inner join nsubunit nsub on ies.subunitatea=nsub.codsubunit
left join nagenda nas on nas.codsubunit=nsub.codsubunit
left join nagenda napartsoc on napartsoc.codpart= np.codpart and napartsoc.SEDIUSOCIAL in (4,5,6,7)
and coalesce(napartsoc.inactiv,0)=0
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
where ies.codies = &lt;WM_CODDOC&gt;
</sqlcampuri>
</row>

<row>
  <codefactc>2</codefactc>
  <den_efcustom>LIDL</den_efcustom>
  <sqlcampuri>select
      nas.GLN as BT_29,  --GLN  vanzator
      '0088' as BT_29_1,  -- identificator schema GLN  vanzator
      napartsoc.GLN as BT_46, -- GLN sediu social cumparator,
      '0088' as BT_46_1, -- identificator schema GLN sediu social cumparator,
      np.den_part||'-'|| napartlivr.obs  as BT_70, -- nume partener + numele sediului de livrare
      napartlivr.GLN as BT_71, -- GLN sediu livrare cumparator,
      '0088' as BT_71_1 -- GLN sediu livrare cumparator
from iesiri ies
inner join npart np on np.codpart=ies.partener
inner join nsubunit nsub on ies.subunitatea=nsub.codsubunit
left join nagenda nas on nas.codsubunit=nsub.codsubunit
left join nagenda napartsoc on napartsoc.codpart= np.codpart and napartsoc.SEDIUSOCIAL in (4,5,6,7) and coalesce(napartsoc.inactiv,0)=0
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
where ies.codies = &lt;WM_CODDOC&gt;</sqlcampuri>
</row>

<row>
  <codefactc>3</codefactc>
  <den_efcustom>MEGA IMAGE</den_efcustom>
  <sqlcampuri>select
      napartlivr.GLN as BT_71, -- GLN sediu livrare cumparator,
      '0209' as BT_71_1 -- GLN sediu livrare cumparator
from iesiri ies
inner join npart np on np.codpart=ies.partener
left join nagenda napartlivr on napartlivr.codagenda=ies.codlocatie
where ies.codies = &lt;WM_CODDOC&gt;
</sqlcampuri>
</row>

</efact_custom>
