简体   繁体   中英

SQL Update Statement in MS Access

Trying to get this query to work in MS Access.

Update Network.Location=Enclave.Location Where Enclave.Site=No AND 
Network.AlternateLocation=Enclave.Location Where Enclave.Site=Yes

I'm not sure how to get this to do exactly what I want which is store Enclave location in network location if the enclave site field is No and if yes store encalve location in alternate location, meaning it would store a blank value in network location in that row.

Key fields update :

Update Network InnerJoin Enclave On Network.ID=Enclave.ID Set 
Network.Location=Enclave.Location Where Enclave.Site=No AND 
Network.AlternateLocation=Enclave.Location Where Enclave.Site=Yes

You should break the command in two:

Update Network SET Location=Enclave.Location Where Enclave.Site=No;
Update Network SET AlternateLocation=Enclave.Location Where Enclave.Site=Yes;
UPDATE Network Inner Join Enclave ON Network.ID=Enclave.ID
SET Network.Location = IIF(Enclave.Site=False, Enclave.Location, ""),
Network.AlternateLocation = IIF(Enclave.Site=True, Enclave.Location, "")

Note: I haven't tried this & guess, this should work.
Also, I have assumed that you will want the field to be updated with blank, if it doesn't satisfy the condition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM