Question : How do I compute a SUM from 2 different tables and divide the Sums?

I have 2 SQL tables…let’s call them tblship and tblreceived.

I am trying to create a view that will give me a resulting ratio of:

1) products shipped that came back as a warranty within that year / all products shipped within that year
2) products shipped that came back as a non-warranty within that year / all products shipped within that year


I tried the code below, but it is overcounting everything due to the join.
-----------------
SELECT year(s.ShipDate) AS Yr,
CAST(SUM(CASE r.[Warranty] WHEN 1 THEN r.BestEstQtyRec ELSE 0 END) AS float) / SUM(s.QtyShip) As WarRatio,
CAST(SUM(CASE r.[Warranty] WHEN 0 THEN r.BestEstQtyRec ELSE 0 END) AS float) / SUM(s.QtyShip) AS NonWarRatio

FROM dbo.tblship s INNER JOIN dbo.tblreceived r ON s.Customer# = r.CustNo AND (year(s.ShipDate)  = year(r.BestEstShipDate))

WHERE s.OrderType = 'S' AND s.QtyShip > 0 AND s.ShipDate >= '1/1/2006'

Group by  year(s.ShipDate)
-----------------

I tried removing the INNER JOIN in order to compute the SUMs separately, but it still seems to be overcounting:
-----------------
SELECT year(s.ShipDate) AS Yr,
CAST(SUM(CASE r.[Warranty] WHEN 1 THEN r.BestEstQtyRec ELSE 0 END) AS float) / SUM(s.QtyShip) As WarRatio,
CAST(SUM(CASE r.[Warranty] WHEN 0 THEN r.BestEstQtyRec ELSE 0 END) AS float) / SUM(s.QtyShip) AS NonWarRatio

FROM         dbo.CHoltzQantelShipped AS s CROSS JOIN
                      dbo.CHoltzReturns AS r
WHERE     (s.OrderType = 'S') AND (s.QtyShip > 0) AND (s.ShipDate >= '10/1/2009') AND (r.Warranty = 'True') AND (r.BestEstShipDate >= '10/1/2009')
----------------

Am I way off here? Is it possible to compute a SUM from 2 different tables then divide the SUMs??? If this were access I'd just create 2 separate queries for each table...do the sums separately then create a 3rd table to divide the SUMs.

Help would be appreciated!! Thanks!

Answer : How do I compute a SUM from 2 different tables and divide the Sums?

As far as I know there are no free add-ons.  VBA is getting pretty old so support my be slowing.

You may still find add-ons to buy but I have never tried them.

What kind of "visual effects" do you want?  You can do a lot  for example see my examples in MS Access forms below.

In the centre I have a waiting "spinner" which is a motion gif.  

Is this kind of thing what you are thinking?

I have found no way of getting away from the square text boxes and comboboxes, but I have (as you can see) on one of the dates when it has focus the border becomes visible with a different color.  Just a little bit of eye candy.

For graphis VBA does not really handle the Alpha transparent channel but you can call the Windows API for example to fade windows in and out or to have forms at 50% so that you can read things behind it - (good for people with one screen)

In one of my examples you can see the "Add New......" This is a Form that fades in and behind it is a black form at about 20% Transparent which give you that Vista look.
 
mirror effect and drop shadowed buttons
mirror effect and drop shadowed buttons
 
 
main form with GIF motion image
main form with GIF motion image
 
 
Fading Forms with vista look background
Fading Forms with vista look background
 
Random Solutions  
 
programming4us programming4us