/* ana b - Ficha/Pa 66305/62856  */

alter table complementonfsaida add  CodVendExt Char(5) default '' 

/* Atualizar a coluna CodVendExt*/ 

insert into ComplementoNfSaida (NumOrd)
Select NumOrd from nfsaidacad where tpo like '2%' and
numord not in(Select NumOrd From ComplementoNfSaida)

update ComplementoNfSaida set CodVendExt =
(Select CodVend From VendedoCad where rpessoa not in (0,7) and 
rPessoa in(Select nValor from aditivo
where rdefinicao = 20202 and
rItem in(Select CodClie From NfSaidaCad 
Where NumOrd = ComplementoNfSaida.NumOrd and CodClie not in(0,7))))
where CodVendExt is null or CodVendExt = ''
