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

0

Please login or register to vote for this query.

(click on this box to dismiss)

Music Fans

Q&A for music historians, critics, and fans

CREATE table #yourtable
    ([Id] int, [Value] varchar(26), [ColumnName] varchar(53))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 'John', 'FirstName'),
    (1, '2.4', 'Amount'),
    (1, 'ZH1E4A', 'PostalCode'),
    (1, 'Fork', 'LastName'),
    (1, '857685', 'AccountNumber'),
    (2, 'John1', 'FirstName'),
    (2, '2.41', 'Amount'),
    (2, 'ZH1E4A1', 'PostalCode'),
    (2, 'Fork1', 'LastName'),
    (2, '8576851', 'AccountNumber')
;


select Firstname, Amount, PostalCode, LastName, AccountNumber
from
(
  select *
  from #yourtable
) d
pivot
(
  max(Value)
  for columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber)
) piv;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results