Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with SQL query

Status
Not open for further replies.

bs2

Programmer
Mar 25, 2005
1
US
I'm going to simplify the tables and queries to eliminate all but the
pertinent info.


We have a table containing detail information on our invoices called
ARDETAIL. Each line item on the invoice is included as a record, each
cash receipt is included as a record and each write off is included as
a record.


The layout is as follows:


OrderNumber
Item
Quantity
Amount


I can get a list of all the unpaid invoices with the following query:


SELECT Customer, OrderNumber, ISNULL(SUM(ROUND(QTY * Amount, 2)),0) AS BALANCE
FROM ARDetail
GROUP BY Customer, OrderNumber
HAVING (ISNULL(SUM(ROUND(QTY * Amount, 2)), 0) <> 0)
ORDER BY Customer, OrderNumber, BALANCE


When an invoice is written off a new record is created with item of '5' and amount of balance * -1. I want to modify my query to return all invoices with balance <> 0 or that have been written off (item will be 5, balance will be 0).


Thanks.


 
You consider an UNION query.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top