Unmatched Append Query to Identify most recent records

skiandy

New member
Local time
Today, 11:32
Joined
Jun 15, 2016
Messages
9
The data source which my DB is based upon is updated frequently, however I can not link directly to it so the tables are exported as a .csv then appended into the Entries table.

Is it possible to create an append query which matches the [Document Number] and then only Updates / Appends if [Rev Date] is more recent than the current document [Rev Date]?


Code:
INSERT INTO Entries ( [Document Number], Title, Revision, [Rev Date] )
SELECT Entries1.[Document Number], Entries1.Title, Entries1.Rev, Entries1.Date
FROM Entries1 LEFT JOIN Entries ON Entries1.[Document Number] = Entries.[Document Number]
WHERE (((Entries.[Document Number]) Is Null));
 
what you need is an Update query with Right Join:

UPDATE ENTRIES AS T1 RIGHT JOIN ENTRIES1 AS T2 ON T1.[DOCUMENT NUMBER]=T2.[DOCUMENT NUMBER]
SET T1.[DOCUMENT NUMBER]=T2.[DOCUMENT NUMBER],
T1.TITLE=T2.TITLE,
T1.REVISION=T2.REVISION
T1.[REV DATE]=T2.[REV DATE]
WHERE
T2.[REV DATE] > T1.[REV DATE] OR ISNULL(T1.[REV DATE]);
 

Users who are viewing this thread

Back
Top Bottom