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)

Software Engineering

Q&A for professionals, academics, and students working within the systems development life cycle

CREATE table #yourtable
    ([Id] int, [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 'John', 'FirstName'),
    (2, '2.4', 'Amount'),
    (3, 'ZH1E4A', 'PostalCode'),
    (4, 'Fork', 'LastName'),
    (5, '857685', 'AccountNumber'),
    (6, 'Jack', 'FirstName'),
    (7, '1.9', 'Amount'),
    (8, 'ZH1E4B', 'PostalCode'),
    (9, 'In', 'LastName'),
    (10, '857681', 'AccountNumber')
;


select
  max(case when columnname = 'FirstName' then value end) Firstname,
  max(case when columnname = 'Amount' then value end) Amount,
  max(case when columnname = 'PostalCode' then value end) PostalCode,
  max(case when columnname = 'LastName' then value end) LastName,
  max(case when columnname = 'AccountNumber' then value end) AccountNumber
from #yourtable

Enter Parameters

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