J
Joan
Hi,
I am trying to run an update query based on three tables in which there is a
many-to-one-to-many relationship and it won't work. Here is the SQL of the
update query I am trying to run:
UPDATE Invoices INNER JOIN (Dogs INNER JOIN Sales ON Dogs.[Dog Number] =
Sales.[Dog Number]) ON Invoices.[Invoice Number] = Sales.[Invoice Number]
SET Dogs.ReturnedInvoice2 = DMin("[Sales].[Invoice
Number]","Sales","[Dogs].[Returned] Is Not Null"), Dogs.ReturnedSaleDate2 =
DMin("[Invoices].[DateSold]","Invoices","Dogs.[Returned] Is Not Null");
I had to add some new fields and change some field names in my Dogs table.
Consequently, since the database is already being used, I need to run some
update queries to get the correct data in the correct fields. There can be
multiple sales for a single dog, because the dog can be returned and resold.
Also there can be multiple dogs listed as sold per invoice. The DateSold
field is in the Invoices table and the Invoice Number and Dog Number are
compound primary keys in the Sales table. A partial table structure is
below:
INVOICES
Invoice Number (Primary Key)
DateSold
SALES
Invoice Number (Primary Key)
Dog Number (Primary Key)
DOGS
Dog Number (Primary Key)
Returned
ReturnedInvoice2
ReturnedSaleDate2
For dogs that are returned, I want to put the minimum [DateSold] value in
the ReturnedSaleDate2 column and the minimum [Invoice Number] value in the
ReturnedInvoice2 column for that particular dog record. How do I do this?
What is the solution if my query is not updateable?
Joan
I am trying to run an update query based on three tables in which there is a
many-to-one-to-many relationship and it won't work. Here is the SQL of the
update query I am trying to run:
UPDATE Invoices INNER JOIN (Dogs INNER JOIN Sales ON Dogs.[Dog Number] =
Sales.[Dog Number]) ON Invoices.[Invoice Number] = Sales.[Invoice Number]
SET Dogs.ReturnedInvoice2 = DMin("[Sales].[Invoice
Number]","Sales","[Dogs].[Returned] Is Not Null"), Dogs.ReturnedSaleDate2 =
DMin("[Invoices].[DateSold]","Invoices","Dogs.[Returned] Is Not Null");
I had to add some new fields and change some field names in my Dogs table.
Consequently, since the database is already being used, I need to run some
update queries to get the correct data in the correct fields. There can be
multiple sales for a single dog, because the dog can be returned and resold.
Also there can be multiple dogs listed as sold per invoice. The DateSold
field is in the Invoices table and the Invoice Number and Dog Number are
compound primary keys in the Sales table. A partial table structure is
below:
INVOICES
Invoice Number (Primary Key)
DateSold
SALES
Invoice Number (Primary Key)
Dog Number (Primary Key)
DOGS
Dog Number (Primary Key)
Returned
ReturnedInvoice2
ReturnedSaleDate2
For dogs that are returned, I want to put the minimum [DateSold] value in
the ReturnedSaleDate2 column and the minimum [Invoice Number] value in the
ReturnedInvoice2 column for that particular dog record. How do I do this?
What is the solution if my query is not updateable?
Joan