SQL How to populate a NULL value -
here scenario:
i have table fields:
policyid membertype memberaddress membercity
there 2 membertype
classifications:
membertype ---------- owners dependents
only owners
linked address , city. when have owner , several family members (dependents) owners row shows address, dependents row address field shows null
(side note: owner , dependent of same family have same policyid
). how can populate address field when there dependent null
address field grab address of owner , populate field.
current results
policyid membertype memberaddress membercity -------------------------------------------------- 1234 owner 9785 sw 197 ct miami 1234 dependent null null 1234 spouse null null
desired results
policyid membertype memberaddress membercity ---------------------------------------------------- 1234 owner 9785 sw 197 ct miami 1234 dependent 9785 sw 197 ct miami 1234 spouse 9785 sw 197 ct miami
thank in advance!
update t set t.memberaddress = t2.memberaddress , t.membercity=t2.membercity table1 t inner join table1 t2 on t.id = t2.id t2.policyid = t.policyid , t.membertype<>'owner' , t.memberaddress null
before running update check ensure updating correct data:
select t.policyid, t2.policyid, t.membertype, t2.membertype, t.memberaddress, t2.memberaddress, t.membercity, t2.membercity table1 t inner join table1 t2 on t.id = t2.id t2.policyid = t.policyid , t.membertype='dependents' , t.memberaddress null
Comments
Post a Comment