August 7th, 2015, 08:34 AM
Join Date: Aug 2015
Time spent in forums: 37 m 29 sec
Reputation Power: 0
Sum and Join
I am attempting to SUM fields from different tables in same DB with a join.
The values are summing, however, the summed values are incorrect?
Perhaps this needs a subquery? However, I am not familiar with how to do that yet?
SUM(CAST(P1.Field1 as float)) as F1A
, SUM(CAST(P2.Field2 as float)) as F2A
, SUM(CAST(P2.Field3 as float)) as F2B
FROM dbo.XXX P1
INNER JOIN dbo.XXX1 P2
ON P1.ID = P2.ID
WHERE P1.Field4 = '12345678' and
P1.Field5 = 'ABCDE'
/*Produces Incorrect amounts
F1A F2A F3A
11168.3 232.92 232.92