Access 2007 Update Query has more Rows than Database - ms-access-2007

I have an Update query that says it's updating 1029 rows, when there are only 994 rows in the database that it's updating.
The query references an external Excel file and updates the "Master Calendar" with "Posted Date" when the batch numbers are equivalent:
UPDATE [Mapped Link] RIGHT JOIN Master_Calendar ON [Mapped Link].Reference = Master_Calendar.[Batch Number] SET Master_Calendar.[Actual Posted Date] = [Mapped Link]. [Entry Date];
Whenever rows get added to the external 'Mapped Link' document, the rows increase on the update query. There are about 2000 rows in 'Mapped Link', so it's not adding the rows from Master Calendar to Mapped Link together.
The data doesn't seem to be updating incorrectly -- all the data is correct. But how can it be updating more rows than it exists? Is it just counting wrong? Thoughts?
Thanks, guys.

You have either duplicates in either Master_Calendar.[Actual Posted Date] or [Mapped Link].[Entry Date]
To check for duplicate dates, you can run a query. For example:
SELECT [Actual Posted Date], Count(ID) AS CountOfID
FROM Master_Calendar
GROUP BY [Actual Posted Date]
HAVING Count(ID)>1
You will need to change ID to the name of the index on your table.

Related

Access SQL: I am trying to update a table with values from the same table

I am trying to import a CSV file exported from Ebay into MS Access.
Ebay cram into one file what should be in two files. So if someone purchases two products, Ebay puts the customer details in one row and the products bought in the following lines.
Customer cruze130613 bought two products, so has information spread over three lines!
What I would like to do is fill the empty User ID column blanks.
So:
Set [User ID] equal same 'User ID' as where [Sales record number] = [Sales record number]
I think the select clause for [Sales record number] should use DISTINCT as is duplicated on >1 rows.
Any help with the SQL code will be appreciated.
Perhaps something along the lines of the following:
update YourTable t1
set t1.[user id] = dlookup
(
"[user id]",
"YourTable",
"[user id] is not null and [sales record number]=" & t1.[sales record number]
)
where t1.[user id] is null
Change both references of YourTable to the name of your table.
Here, the domain aggregate function DLookup is used to acquire the value of the User ID field for a record meeting the supplied criteria (in this case where User ID is not null, and where the sales record number is equal to that of the record being updated).
There are other ways to achieve the same result, but DLookup is used here to retain the 'updateability' of the query in MS Access.
Thank you Lee for your suggestion.
As far as I can see Ebay only export these pseudo CSV files.
I had another look today and managed to find a solution. I wonder which would be more efficient yours or mine?
UPDATE tEbImportRaw AS eir1
INNER JOIN tEbImportRaw AS eir2
ON eir1.[Sales Record Number] = eir2.[Sales Record Number]
SET eir1.[User ID] = eir2.[User ID];

Access Update Query Updating Both Tables of the SET Statement

I have created an update query in MS Access. In the query there are two tables. One is the table I want to update (000DeleteMeNames), and the other is a linked table (it's actually a list) in Sharepoint (Work Orders). Every time I run the query, it does what it is supposed to and updates 000DeleteMeNames like it's supposed to, however it also modifies the joined records in the Sharepoint list Work Orders. No actual changes are made to the Sharepoint records, however the modified date changes and an alert is sent to me that the Sharepoint records have changed.
UPDATE 000DeleteMeNames INNER JOIN [Work Orders]
ON WO_Num = [Work Orders].[Work Order Number])
AND ([000DeleteMeNames].[Date-Forecast] = [Work Orders].[Work Order Date])
SET [000DeleteMeNames].DummyField = [Work Orders].[Manager];
Is there a way to change my SQL so that the Sharepoint list is not updated, and only the records in the 000DeleteMeNames table that are native to Access are updated? Am I doing something wrong in the SQL above? Thanks in advance.
Try this:
UPDATE 000DeleteMeNames
SET [000DeleteMeNames].DummyField = [Work Orders].[Manager]
FROM 000DeleteMeNames INNER JOIN [Work Orders]
ON WO_Num = [Work Orders].[Work Order Number])
AND ([000DeleteMeNames].[Date-Forecast] = [Work Orders].[Work Order Date]);

Update query not updating the full field

I have two tables, Actual Use and Budget. I need to update my [Actual Use].Goals with my monthly Budget.goals. I have an update query:
UPDATE [Actual Use]
INNER JOIN Budget ON [Actual Use].Property_ID = Budget.Property_ID
SET
[Actual Use].Goal = [Budget].Goal
WHERE
[Actual Use].Date = [Budget].Date
This query updates my Actual Use table but only for one month. 1/1/2016. Both Actual Use and Budget have a date field and all dates are entered with the first of each month so 1/1/2016, 2/1/2016 etc... Why is my update only working on one month and not every month where the Property_ID and month are the same on both tables?
Edit
The Acutal Use Table has the following fields in this order
Property_Id, Date, Use, Goal and the Budget Table has Property_ID, Date, Goal
I agree with the comment by Olivier. You need to join on both ID and Date.
Depending on what your table keys are, the above listed query could produce a One to Many or Many to Many result, in which, the program doesn't know which goal to assign. I suppose the Where clause may catch the many to many circumstance, but in my opinion, could produce some weird behavior.
Possible solution:
UPDATE [Actual Use]
INNER JOIN Budget ON [Actual Use].Property_ID = Budget.Property_ID
AND [Actual Use].Date = Budget.Date
SET
[Actual Use].Goal = [Budget].Goal
On a side note, it seems like the data is a bit repetitious? Presuming there was no 'goal' in table [Actual Use], you could still reference the data by the following:
SELECT * FROM [Actual Use] au
JOIN Budget b on au.Property_ID = b.Property_ID AND
au.Date = b.Date

Need help structuring SQL query to find collisions tied to same key value

I'm working on merging individual Access databases into a single SQL database, but there are collisions that need to be sorted out first.
For example, the table in each database that holds course/class information (it's school-related) uses the [Course ID] as a key value, but the other columns in that table don't necessarily match across all of the individual Access databases. So, a [Course ID] of "0106" might exist in multiple databases, and I need to make sure that the other 19 columns associated with that [Course ID] are identical in the other access databases.
I've already compiled the data from all of the access databases into an Access database as an aggregate with all of the duplicated/colliding data.
I've already developed a query to find all of the duplicate [Course ID] values, but I need another query to find any other inconsistent data between records.
How can I structure a SQL query to find records with duplicate [Course ID] values, but only the ones where one of the other columns has an inconsistency?
I have two tables that I'm working with; CHI(fields Expr1000,School) and CRS (fields Expr1000,Course ID, Course title).
The query I'm using atm is:
SELECT CRS.[Course ID], CRS.[Course title], CHI.Name
FROM CHI RIGHT JOIN CRS ON CHI.Expr1000 = CRS.Expr1000
WHERE (
((CRS.[Course ID]) In
(SELECT [Course ID] FROM [CRS] As Tmp GROUP BY [Course ID] HAVING Count(*)>1 ))
AND ((CRS.Expr1000)=[CHI].[School]))
ORDER BY CRS.[Course ID];
This generates a list of all records with duplicate [Course ID]s, though I'd prefer a list that will exclude occurrences where all the records with a given [Course ID] have matching [Course title].
E.g., If all records with Course ID=106 also have matching [Course Title], then they should be excluded.
I'm not sure if I should try to consolidate everything into a single query or create multiple queries to whittle the data down, and I'm not sure how to structure the queries for the data I desire.
You could do something like this:
SELECT *
FROM table1
LEFT JOIN table2 ON table1.key = table2.key
and (
table1.property1 <> table2.property1
or table1.SomeOtherProperty <> table2.SomeOtherProperty
-- etc
)
this would return records from the tables that have a matching key, but at least one other column in the table is not matching - note using column stubs here, plug in your own column names.

Left Join Doesn't Return Unmatched Rows As Null

On my Left Table I have all EMP Information joint with all possible Asset, SO all Employees are assigned to take all courses listed in the database. AND the Right Table I have Only Employees who has taken or in process of taking the course.( Both tables are queries and their results are correct)
I would like to do Left join between two tables (queries) so I get All Employees from Left-Table joint Right-Table with new columns (Completion date & Completion status)!
However, when I do left-join it returns all my rows and fills the blanks with the two possibilities for Completion Status which is Completed OR in Progress). The most stupid thing happens when I add Completion date and returns some random dates and fills all rows for Completion Dates and repeats those rows for following asset titles.
My result should be a list of all EMP joint with required courses with the status of course, this person has completed the course or not and I would like to get null for all those non related rows. Will you be kind and check my code and let me know what can cause this problem? Thank you
SELECT qryEmployeeCourse.[EMP ID], qryEmployeeCourse.Name, qryEmployeeCourse.Role, qryEmployeeCourse.Location, qryEmployeeCourse.Region, qryEmployeeCourse.[Asset ID], qryEmployeeCourse.[Asset Title], qryCourseStatus.[Completion Status]
FROM qryEmployeeCourse LEFT JOIN qryCourseStatus ON qryEmployeeCourse.[EMP ID] = qryCourseStatus.Username
GROUP BY qryEmployeeCourse.[EMP ID], qryEmployeeCourse.Name, qryEmployeeCourse.Role, qryEmployeeCourse.Location, qryEmployeeCourse.Region, qryEmployeeCourse.[Asset ID], qryEmployeeCourse.[Asset Title], qryCourseStatus.[Completion Status]
ORDER BY qryEmployeeCourse.Name, qryEmployeeCourse.Role, qryEmployeeCourse.Location;
http://i.stack.imgur.com/0zNVz.png here is the pic of my tables and result.
It looks to me that your LEFT JOIN should be
qryCourseStatus ON qryEmployeeCourse.[EMP ID] = qryCourseStatus.Username AND qryEmployeeCourse.AssetID = qryCourseStatus.AssetID
Otherwise you will be getting a cross join (all rows in qryEmployeeCourse with all rows in qryCourseStatus, for each employee ).
In the first set of results in your screenshot, you are only getting two rows because the employees records in the qryCourseStatus only has two distinct statuses Completed and In progress, and your group by is removing all the other duplicates.
You get a lot more rows in the second set of results, because you are adding Completion Date which has 7 distinct values for this employee.