Hey there
I’ve got a table like this:
Create Table PersonAgent (
PersonID varchar2(10) not null,
AgentID varchar2(10) not null,
Address varchar2(50),
City varchar2(50),
Country varchar2(50)
)
Well I need to generate this table new, coze some data are incorrect.
If PersonID and AgentID are the same then I can take the other attributes as they are but if they are not the same then I need to read from another table.
Little Example:
INSERT INTO PersonAgent_copy(PersonID, AgentID, Address, City, Country)
Select Pa.Persid, Pa.Agentid,
(Case
When Pa.Personid = Pa.Agentid
Then pa.Address
ELSE (SELECT p.Address
FROM Person p
Where Pa.Agentid = P.Personid)),
(Case
When Pa.Personid = Pa.Agentid
Then pa.City
ELSE (SELECT p.City
FROM Person p
Where Pa.Agentid = P.Personid)),
(Case
When Pa.Personid = Pa.Agentid
Then pa.Country
ELSE (SELECT p.Country
From Person P
Where Pa.Agentid = P.Personid))
FROM PersonAgent pa
(There are some more attributes that works the same)
What is the fastest way to do this?