Update Query

R

Ray Todd

I am trying to create an update query that would follow the following rules.
I am banging my head against the wall in an effort to write the SQL but don't
seem to wrap my brain around it (keeping in mind that I am not by any means
an expert).

What I am wanting to do is this:

1. Execute the UPDATE query, which will update the address fields in the
address table if the DateAddressUpdated field is null.

2. Update the AddressUpdateDated to the date that the address fields were
updated.

I have created the UPDATE query to do number 1, however, how do I integrate
1 and 2 into one query so that after the UPDATE query has updated the address
fields, it will add the date to the AddressUpdateDate field?

This is the SQL that I have to execute number 1.

UPDATE taDEFENDANT RIGHT JOIN NewAddresses ON taDEFENDANT.PartyNumber =
NewAddresses.PartyID
SET taDEFENDANT.Address1 = [NewAddresses].[NewAddress], taDEFENDANT.Address2
= [NewAddresses].[NewAddress2], taDEFENDANT.City = [NewAddresses].[NewCity],
taDEFENDANT.State = [NewAddresses].[NewState], taDEFENDANT.ZipCode =
[NewAddresses].[NewZip]
WHERE (((taDEFENDANT.DateAddressUpdated) Is Null));


Thanks,

Ray.
 
J

John Spencer

If you want to use Today's date then the following should work for you

UPDATE taDEFENDANT RIGHT JOIN NewAddresses
ON taDEFENDANT.PartyNumber = NewAddresses.PartyID
SET taDEFENDANT.Address1 = [NewAddresses].[NewAddress]
, taDEFENDANT.Address2 = [NewAddresses].[NewAddress2]
, taDEFENDANT.City = [NewAddresses].[NewCity]
, taDEFENDANT.State = [NewAddresses].[NewState]
, taDEFENDANT.ZipCode = [NewAddresses].[NewZip]
, taDEFENDANT.DateAddressUpdated = Date()
WHERE (((taDEFENDANT.DateAddressUpdated) Is Null));

Question 1: Why a RIGHT JOIN? I would think you would want an INNER JOIN.

Standard Warning: Backup your data first, since this can't be undone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

update two fields at once 1
Access update query 2
Update Query 4
What's wrong with this query? 6
If statement in Update query 7
Appending null data and moving! 4
IIF update query 1
update query 2

Top