I have 2 very simple tables to join but I am missing somewhere badly that I am not getting the desired output:
Table #1:
Table #2:
Desired output:
Query:
create table #temp1
(
client_id int,
identifier int,
pp_id int,
ch_id int,
code varchar(20),
program varchar(20),
startdate date,
enddate date,
ssc varchar(50)
)
insert into #temp1
values (9908,789654123,1567,1566,'OP','xASMT','1/1/2019','1/4/2019','A201901044F010134NNN01D 151 143 093 ')
create table #temp2
(
client_id int,
identifier int,
pp_id int,
ch_id int,
code varchar(20),
program varchar(20),
startdate date,
enddate date,
ssc varchar(20)
)
insert into #temp2
values(9908,789654123,1574,1573,'OP','SU1','1/1/2019','1/4/2019',NULL)
--My query:
select
t1.client_id, t1.identifier,
concat(t1.code, t1.startdate, t1.enddate, t1.ssc),
concat(t2.code, t2.startdate, t2.enddate, t2.ssc)
from
#temp1 t1
left join
#temp2 t2 on t1.client_id = t2.client_id and t1.identifier = t2.identifier
I am still a learner and pardon me if there are any mistakes here. Any help?!


