CREATE table #yourtable ([Id] int, [Value] varchar(6), [C...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Christianity

Q&A for committed Christians, experts in Christianity and those interested in learning more

CREATE table #yourtable
    ([Id] int, [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 'fname', 'FirstName1'),
    (1, 'lname', 'LastName1'),
    (2, 'fname', 'FirstName2'),
    (2, 'lname', 'LastName2')
;


select fname, lname
from
(
  select value, columnname
  from #yourtable
) d
pivot
(
  max(columnname)
  for value in (fname, lname)
) piv;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results