create table #tb (record_id int, obj_id char(4), reference char(10)) insert #tb values(1, 'Btn1', 'forward') insert #tb values(1, 'Btn2', 'backward') select record_id, min(case when obj_id = 'btn1' then reference end) as btn1, min(case when obj_id = 'btn2' then reference end) as btn2 from #tb group by record_id