Я смоделировал ваш пример в следующих запросах:
create table final_value(bridge_id varchar(40), material_id int, height int, width int, thickness int);
create table temp_value(bridge_id varchar(40), material_id int, height int, width int, thickness int);
insert into final_value values ('dff12cd6',4,0,0,0),('15b54528',4,0,0,0),('486a0aa7',4,0,0,0);
insert into temp_value values ('dff12cd6',4,5,0,0),('15b54528',4,6,7,9),('486a0aa7',4,0,0,0);
select a.bridge_id as 'Bridge ID', a.measure_name AS 'Measure Name', a.final_val as 'Final Value', ISNULL(b.temp_val, 0) as 'Temp Value ' from
(select bridge_id,
measure_name,
final_val
from final_value
unpivot
(
final_val
for measure_name in (height, width, thickness)
) unpiv) a
left join
(select bridge_id,
measure_name,
temp_val
from temp_value
unpivot
(
temp_val
for measure_name in (height, width, thickness)
) unpiv) b
on
a.bridge_id = b.bridge_id and
a.measure_name = b.measure_name;
вы также можете отослать то же самое от rextester здесь: https://rextester.com/WFHO83710