select distinct a.type, a.invoice, a.datecr, a.to_1, a.from_1, a .ctry_to, a.payout, a.payin, a.idbank, a.netamt, a.telex, a.urgency, a.exchange, a.handling, a.total, a.status, a.copy, a.receipt, b.tipo, b.idnbr, b.zona, b.castra,@datecr, b.val_comi , a.branchpayer , e.postto, e.idnbr, e.zona, e.castra,c.city , a.iva from invoice a inner join xbranc b on substring(a.invoice,1,3)=b.idnbr inner join banks c on a.idbank=c.idbank inner join banks d on c.pagador=d.idbank inner join xbranc e on d.brcnb=e.postto where (a.receipt between @datecr+ ' 00:00:00' and @datecr1+ ' 2 3:00:00') and e.tipo ='n' and (a.status='P') and a.type='M' and (a.branchpayer is not null and len(rtrim(a.branchpayer)) = 3 ) and (a.branchpayer in (select branc from xoficinas where matriz in(2)) or a.branchpayer in (select branc from xoficinas where online=0 and matr iz=0 and castra='z' and zona=5 ))--and branc not in ('577','641')) ) and substring(a.idbank,1,3) not in ('326','037') and b.tipo in ('u','n','r','h'); delete from xpagado6 where postto in ('n52'); delete from xpagado6 where substring(invoice,1,3) in (select bra nc from xoficinas where castra='t'); --update hrecicorrdbk set fecha_pag=x.receipt,pagx='T',comisionp ag=x.netamt*(0.50/100) update hrecicorrdbk set fecha_pag=x.receipt,pagx='T',comisionpag =0.47 from hrecicorrdbk inner join xpagado6 x on x.invoice=hrecicorrdbk.invoice where x.tipo not in ('N') --giros pagados Nacionales (captados por DELBANK pagados por Ofi cinas de DTravel --update xpagcon set ctacor='T',handling=x.netamt*(0.50/100) update xpagcon set ctacor='T',handling=0.47 from xpagcon inner join xpagado6 x on x.invoice=xpagcon.invoice where x.tipo in ('N')