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

Whats wrong with this query?

Status
Not open for further replies.

Waynest

Programmer
Jun 22, 2000
321
GB
Can someone tell me whats wrong with this?
It works when the total returned by each SELECT is > 0, but if either of the 2 SELECTs returns nothing then the GrandTot is NULL (they differ by the OpEmp & OpDate numbers). Obviously I just want an overall total regardless...

SELECT GrandTot =
(SELECT SUM(T.Qty / 12) * (R.Rate * P.StdMinVal) AS TotEarned FROM Ticket T
INNER JOIN Product P ON (T.StyleCode = P.Style AND T.Size = P.Size)
INNER JOIN YieldRate R ON R.Code = P.YieldCode
WHERE (T.OpEmp1 = 'A1898' AND T.OpDate1 = '20010201') AND T.StyleCode = 'AY4' AND T.Size = 3
GROUP BY R.Rate, P.StdMinVal)
+
(SELECT SUM(T.Qty / 12) * (R.Rate * P.StdMinVal) AS TotEarned FROM Ticket T
INNER JOIN Product P ON (T.StyleCode = P.Style AND T.Size = P.Size)
INNER JOIN YieldRate R ON R.Code = P.YieldCode
WHERE (T.OpEmp2 = 'A1898' AND T.OpDate2 = '20010201') AND T.StyleCode = 'AY4' AND T.Size = 3
GROUP BY R.Rate, P.StdMinVal)

 
Cheers guys, the UNION did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top