sql - MS Access : Filling column values conditionally -
sql - MS Access : Filling column values conditionally -
i have read few q&a's here filling in condition-based values in access using switch , iff statement. relatively new access, little help much appreciated.
i have 2 tables, owner
, pet
.
table owner
has next fields:
ownerid , ownername , pettype , petcommonname , ownsagarden
table pet
has next fields:
species , commonname , needsagarden
table pet maps scientific names of pet animals generic, commonly known ones. table owner has values ownerid, ownername, petcommonname , ownsagarden existing in table. column pettype needs updated based on status table pet.
i want like:
if pet.commonname = 'dog' , pet.needsagarden = 'yes', owner.pettype = 'outgoing dog', else if pet.commonname = 'dog' , pet.needsagarden = 'no', owner.pettype = 'indoor dog', else if pet.commonname = owner.petcommonname, owner.pettype = corresponding vale pet.species.
i have tried using switch statement. first 2 conditions evaluated , table getting updated perfectly. however, 3rd status doesn't seem give desired results.
after lot of tinkering alternatives, have managed solve problem using iif statement..
i changed code to
class="snippet-code-html lang-html prettyprint-override">update pet inner bring together owner on pet.commonname = owner.petcommonname set owner.pettype = iif(pet.petcommonname = 'dog', iif(pet.needsagarden = 'yes', 'outgoing dog', 'indoor dog'), pet.species);
it working.. guys before posts help me come this..
sql ms-access
Comments
Post a Comment