I have three databases that interact with each other. One is a vendor asset management db that houses vendors that my company uses, their contact information as well as contract data. Another db contains data on Purchase Orders that we use to pay these Vendors. The third database is an invoice database that houses data on invoices paid to the vendors.
I want to build a query that will allow me to see how much we've spent on all vendors for a certain time frame. I am able to do a query that pulls cumulative spending, but when I put in a date range (based on the invoice date), the query returns a dataset that has multiple entries of certain vendors who have submitted multiple invoices during that period.
Here is how the relationships work:
From vendor db:
tblCompany
CompanyID
CompanyName
...
From PO db:
POID
CompanyID
...
From Invoice db:
InvoiceID
POID
AirCost
DeliveryCost
...more Cost fields
Here is the SQL (with the summation narrowed down for brevity's sake):
How do I go about getting the multiple entries to combine?
I want to build a query that will allow me to see how much we've spent on all vendors for a certain time frame. I am able to do a query that pulls cumulative spending, but when I put in a date range (based on the invoice date), the query returns a dataset that has multiple entries of certain vendors who have submitted multiple invoices during that period.
Here is how the relationships work:
From vendor db:
tblCompany
CompanyID
CompanyName
...
From PO db:
POID
CompanyID
...
From Invoice db:
InvoiceID
POID
AirCost
DeliveryCost
...more Cost fields
Here is the SQL (with the summation narrowed down for brevity's sake):
Code:
SELECT tblCompany.CompanyName, Sum([tblInvoices.AirCost]+[tblInvoices.DeliveryCost]) AS [Total Spent], tblInvoices.InvoiceDate
FROM tblCompany INNER JOIN (tblInvoices INNER JOIN tblPO ON tblInvoices.POID = tblPO.POID) ON tblCompany.CompanyID = tblPO.CompanyID
GROUP BY tblCompany.CompanyName, tblInvoices.InvoiceDate
HAVING (((tblInvoices.InvoiceDate)>=#1/1/2006# And (tblInvoices.InvoiceDate)<=#1/31/2006#));
How do I go about getting the multiple entries to combine?