SQL Update Statement in MS Access

2019-08-07 20:53发布

问题:

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

回答1:

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.



回答2:

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;