High All,
I have a query with the following SQL:
SELECT tblBilling.AccountID, tblDemographics.[LastName/BusinessName], tblPaymentAllocations.PayID, tblBilling.DateWorked, tblBilling.InvoiceTotal, tblBilling.InvoiceNo, tblBilling.DateBilled, tblPaymentAllocations.AmountAllocated, tblPayment.DatePaid, [invoicetotal]-[amountallocated] AS Balance
FROM tblPayment RIGHT JOIN (tblDemographics INNER JOIN (tblBilling LEFT JOIN tblPaymentAllocations ON tblBilling.InvoiceNo = tblPaymentAllocations.InvoiceNoReference) ON tblDemographics.AccountID = tblBilling.AccountID) ON tblPayment.PayID = tblPaymentAllocations.PayID
ORDER BY tblDemographics.[LastName/BusinessName], tblBilling.InvoiceNo, tblPayment.DatePaid;
The goal is to show the balance on an invoice after a payment allocation has been applied. This works fine. My problem is that when there has not been anything allocated the query returns a null value when what I want it to return is the original InvoiceTotal.
My question, is there a way to do an if/than statement in a query that tells that query that if the balance field is null than the field = InvoiceTotal? If so, how would I write this or, is there a better/different approach.
Thanks,
Leesha