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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculations using a Union query 1

Status
Not open for further replies.

Stewman

MIS
Jan 23, 2002
79
US
Hello,

I have a query consisting of 3 queries all union-ed together each returning a specific count. My end result looks like this:

Kount Type
786 Duplicates
11737 Orders
38503 Calls

What I want is to do the following calculation within this sql query.

(Calls + Orders) - Duplicates

Is this possible?

Thanks,

Chris
 
One way:
SQL:
SELECT SUM(Kount*CASE WHEN Type='Duplicates' THEN  -1 ELSE 1 END) AS CalculatedAmount
FROM yourUnionQuery

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV it worked great. Exactly what I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top