select no, nome, estab, nome2, morada, vendedor, vendnm, fref as refint, ncont, local,
telefone, tlmvl, fax, email, url, obs, obsdoc, segmento, bino, bidata, bilocal, naturalid,
nascimento, bic as swift, iban, (case moeda when 'EURO' then 'EUR' else moeda end) as moeda,
substring(codpost, 1, 8) as codpost, tipo, zona, mesesnaopag, inactivo, c1func as cfuncao1,
c2func as cfuncao2, contacto as cnome1, c2tacto as cnome2, c1email as cemail1, c2email as cemail2,
c1tele as ctelefone1, c2tele as ctelefone2, tabiva, vencimento, autofact, preco, desconto, descpp,
tipodesc, clivd, isperson, eplafond, alimite, nocredit, naoencomenda,
(case codmotiseimp
when 'M08' then 'af1-8a2d-b6de-f55daf7f116'
when 'M10' then 'af1-9a2d-b6de-f55daf7f117'
when 'M14' then 'af4-1a2d-b6de-f55daf7f119'
when 'M12' then 'af8-1a2d-b6de-f55daf7f118'
when 'M02' then 'aU1-1a2d-b6de-f55daf7f113'
when 'M04' then 'aU1-1a2d-b6de-f55daf7f114'
when 'M06' then 'aU1-1a2d-b6de-f55daf7f115'
when 'M07' then 'df1-7a2d-b6de-f55daf7f115'
when 'M15' then 'df8-1a2d-b6de-f55daf7f119'
when 'M16' then 'df8-1a2d-b6de-f55daf7f120'
when 'M20' then 'df8-1a2d-b6de-f55daf7f121'
when 'M11' then 'df8-7a2d-b6de-f55daf7f117'
when 'M13' then 'df9-1a2d-b6de-f55daf7f118'
when 'M01' then 'du1-1a2d-b6de-f55daf7f112'
when 'M03' then 'dU1-1a2d-b6de-f55daf7f113'
when 'M05' then 'dU1-1a2d-b6de-f55daf7f114'
when 'M08' then 'z202009061355244160000002'
when 'M09' then 'z202009061357476830000002'
when 'M99' then 'z202009061417469910000002'
else ''end) as miseimpstamp,
(case taxairs when 0.00 then 0 else 1 end) as sujirs,
diaspag as diames, codpais as pncont
from cl (nolock) inner join cl2 on cl.clstamp = cl2stamp