>>create sql view vInvoice as ; >>Select ; >> A.invoice_ID, ; >> INT(A.billing_ID) AS billing_ID, ; >> INT(A.site_ID) AS site_ID, ; >> PADR(A.invoicenum,10) as invoicenum,; >> PADR(A.billrefno,20) as billrefno ; >> A.isedi, ; >> A.invdate, ; >> A.datezero,; >> A.arnotes, ; >> A.autopay, ; >> A.invtype,; >> A.sbill_ID, ; >> A.issbill, ; >> A.insuser_ID,; >> A.upduser_ID, ; >> A.insdttm, ; >> A.upddttm,; >> A.busgrp_ID,; >> B.arcode,; >> B.grpcode,; >> B.inco, ; >> B.name1,; >> B.name2, ; >> B.addr1,; >> B.addr2, ; >> B.city, ; >> B.state,; >> B.zip,; >> B.country,; >> B.isedi210,; >> B.isinvprint,; >> 0000000.00 + Sum(Iif(C.xntype = 'CHARGE' And C.p3_ID = A.billing_ID,; >> ROUND(C.rate*C.qty+C.addamt,2),0000000.00)) As OrigAmt,; >> 0000000.00 + Sum(Iif(C.xntype = 'CHARGE',Round(C.rate*C.qty+C.addamt,2), -1*Round(C.rate*C.qty+C.addamt,2))) As Balance ; >> FROM Invoice A ; >> JOIN Sites B On A.site_ID = B.site_ID ; >> JOIN FinXn C On A.invoice_ID = C.p2_ID And C.isgl And C.datepost <= Date() And (C.xntype = 'CHARGE' Or C.xntype = 'RECEIPT' Or C.xntype = 'ADJUST') ; >> GROUP By 1 >>>>