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

0

Please login or register to vote for this query.

(click on this box to dismiss)

Amateur Radio

Q&A for amateur radio enthusiasts

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'),
    (11, 'ZH1E4A', 'PostalCode'),
    (11, 'Fork', 'LastName'),
    (11, '857685', 'AccountNumber'),
    (2, 'John1', 'FirstName'),
    (2, '2.41', 'Amount'),
    (22, 'ZH1E4A1', 'PostalCode'),
    (22, 'Fork1', 'LastName'),
    (22, '8576851', 'AccountNumber')
;


select Id,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