Tengo el siguiente codigo, y solo necesito agregar el calculo de dias entre PAGOS RECIBIDOS y FACTURA. No se como agregarlo, les envio el Query que llevo.
SELECT
t3.docnum ,
t1.Docnum , t1.docdate as 'Pago Recibido', t3.Docdate as 'Factura', t1.cardcode , t1.cardname ,
t1.doctotal , t1.trsfrsum , t1.trsfrdate ,
t1.trsfrref ,t4.acctname, t1.doccurr , t1.ref1,t1.ref2,t1.counterref,t1.comments, t2.sumapplied , t3.Docdate
from orct t1
left outer join rct2 t2 on t1.docnum = t2.docnum
left outer join oinv t3 on t2.docentry = t3.docentry
left outer join oact t4 on t1.Trsfracct = t4.acctcode
where t3.docdate between [%0] and [%1]