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)

Emacs

Q&A for those using, extending or developing Emacs

CREATE table #yourtable
    ([Id] int, [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 'John', 'FirstName'),
    (1, 'John', 'Amount'),
    (1, 'John', 'PostalCode')
;


select Firstname, Amount, PostalCode
from
(
  select value, columnname
  from #yourtable
) d
pivot
(
  max(value)
  for columnname in (Firstname, Amount, PostalCode)
) piv;

Enter Parameters

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