I'm trying to build a SQL Sum statement to sum data from different tables. Each table has a SalesRep field in common. I'm having a bit of trouble figuring out how to to construct the SQL correctly.
I know the below syntax is wrong and won't work but I'm just not a SQL expert. I'm sure it's something simple. Can someone help me please?
SELECT SalesRepID, SUM(SELECT SalesRepID, Sum(tblClientAdditions.Amount) AS Subtotal
FROM tblClientAdditions GROUP BY SalesRepID + SELECT SalesRepID,
Sum(tblAccounts.ReceivedAmount) AS Subtotal1
FROM tblAccounts GROUP BY SalesRepID) FROM tblSalesReps;
There is no relation between the tables, right?
Than maybe something like this?
Greetings
I added IsNull because if one of the columns are null you will get null in the answer and you don't want that.
This works for me.