select SalesReps.SalesRepId,sum(InvoiceItemCommissions.Amount) + sum(ToolCheckCommissions.Amount) From SalesReps inner join Commissions On Commissions.SalesRepId = SalesReps.SalesRepId inner join InvoiceItemCommissions On Commissions.CommissionId = InvoiceItemCommissions.CommissionId inner join ToolCheckCommissions on ToolCheckCommissions.CommissionId = Commissions.CommissionId where ToolCheckCommissions.Paid= 0 AND InvoiceItemCommissions.Paid=0 group by SalesReps.SalesRepId
I am trying to make this so that in the case InvoiceItemCommissions and ToolCheckCommissions have a record with the same CommissionId but one is paid and the other is not, I will get the sum. Currently if the commissionID is the same and one is paid and one is not, that record will not be returned.. For example
InvoiceItemCommissions
CommissionId=1
Amount=3
Paid=0
ToolCheckCommissions
CommissionId=1
Amount=3
Paid=1
I need this query to return 3 For the Amount Column, Currently it just skips that record becuase of the where clause.
Im kindof newbie with sql as you can tell, so any help would be greatly appreciated
I am trying to make this so that in the case InvoiceItemCommissions and ToolCheckCommissions have a record with the same CommissionId but one is paid and the other is not, I will get the sum. Currently if the commissionID is the same and one is paid and one is not, that record will not be returned.. For example
InvoiceItemCommissions
CommissionId=1
Amount=3
Paid=0
ToolCheckCommissions
CommissionId=1
Amount=3
Paid=1
I need this query to return 3 For the Amount Column, Currently it just skips that record becuase of the where clause.
Im kindof newbie with sql as you can tell, so any help would be greatly appreciated