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

Help with a complicated Join Clause 1

Status
Not open for further replies.

spons

Programmer
Mar 17, 2004
18
US
I am trying to figure out how to get this query to return an EFT Amount also the Sum of the Direct Deposit Amounts. Sometimes there are no direct deposit Amounts, So i need to use Outer Joins. I almost have it figured out, but im getting an extra row with all of the Direct Deposits in the data base sum'd up. Here is my SQL and the results

Code:
select Customers.CustomerId,Customers.Description as Customer,EFT.Amount as EFT,sum(Checks.Amount) as DirectDeposit,'Note' as Note,EFT.EFTId,ACHBATCHS.ACHBatchId as ACHId from ToolCheckBatches full outer join AchBatchs on AchBatchs.ToolCheckBatchId = ToolCheckBatches.ToolCheckBatchId full outer join AchBatchItems on AchBatchItems.AchBatchId = AchBatchs.AchBatchId inner join Invoices on Invoices.InvoiceId = ToolCheckBatches.InvoiceId full outer join EFT on EFT.InvoiceId = Invoices.InvoiceId inner join Customers on Customers.CustomerId = ToolCheckBatches.CustomerId full outer join ToolChecks on ToolChecks.ToolCheckId=AchBatchItems.ToolCheckId full outer join Checks on Checks.CheckId=ToolChecks.CheckId group by Customers.CustomerId,Customers.Description,EFT.Amount,EFT.EFTId,AchBatchs.AchBatchId,ToolCheckBatches.ToolCheckBatchId

NULL	NULL	NULL	7099.5400	Note	NULL	NULL
2	Accurate Auto Body	1007.82000	NULL	Note	22	NULL
5	Especially Imports, Inc.	659.58000	588.6200	Note	21	24

The results are correct except for the first record, I need help avoiding that record any suggestions would be appreciated.
 
If you must always get the customer back use right or left joins instead of full outer joins.
 
I changed all of the full outer joins to left outer joins and get the results I needed Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top