Good morning, I hope this is an easy one for you experts. I have a temporary table that has a field called 'mailer'.
The 'mailer' field can hold mutiple values concantenated from a dual join.
I am including the design, as well as the joins.
-- code to create the tables and data
create table table_a
(
ContactID varchar(100),
Mailer varchar(max)
)
create table table_b
(
ContactID varchar(100),
MailerID varchar(100)
)
create table table_c
(
MailerID varchar(100),
MailerName varchar(100)
)
insert into table_a
VALUES ('1',''),
('2',''),
('3',''),
('4',''),
('5','');
insert into table_B
VALUES ('1','MAIL1'),
('1','MAIL2'),
('1','MAIL3'),
('2','MAIL2'),
('2','MAIL4'),
('2','MAIL5'),
('3','MAIL3'),
('4','MAIL4'),
('5','MAIL5');
insert into table_c
VALUES ('MAIL1','Mailer1'),
('MAIL2','Mailer2'),
('MAIL3','Mailer2'),
('MAIL4','Mailer4'),
('MAIL5','Mailer5');
Relationships would be like this:
- Table_A.Contactid may be in Table_B (ContactID)
- Table_B.MailerID would alwasy be in Table_C (Mailerid)
What I need is an update that will run thru table_A and update the actual Mailer name from Table_C if the contactID in Table_B matches the contactID in table_A
After the update I need table_A to look like this:
Table_A.ContactID, Table_A.Mailer
('1','Mailer1;Mailer2;Mailer3')
('2','Mailer2,Mailer4,Mailer5')
('3','Mailer3')
('4','Mailer4')
('5','Mailer5')
SELECT * FROM table_a
drop table table_a
drop table table_b
drop table table_c