I have two tables #Service and #Cross.I would like to convert the multiple rows in #Service into single row based on the value available in #Cross.
create table #Service
(
id int,
code char(2)
);
create table #Cross
(
code varchar(2),
switch varchar(10)
);
create table #ServiceMap
(
id int,
switch1 char(1),
switch2 char(1),
switch3 char(1),
switch4 char(1)
);
insert into #Service
select 1001,'50' union
select 1001,'60' union
select 1001,'70' union
select 1002,'60' union
select 1003,'50' union
select 1003,'70' union
select 1004,'80'
insert into #Cross
select '50','switch1' union
select '60','switch2' union
select '70','switch3' union
select '70','switch4'
insert into #ServiceMap
select 1001,'Y','Y','Y','N' union
select 1002,'N','Y','N','N' union
select 1003,'Y','N','Y','N' union
select 1004,'N','N','N','Y'
Please help me to write a query to get result in #ServiceMap like below.
id switch1 switch2 switch3 switch4
1001 Y Y Y N
1002 N Y N N
1003 Y N Y N
1004 N N N Y
(4 rows)Execution time: 0.008 seconds
Thanks,
Binto