test GE

0

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

CREATE table #yourtable
    ([Id] int, [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 'John', 'FirstName'),
    (1, '2.4', 'Amount'),
    (1, 'ZH1E4A', 'PostalCode'),
    (1, 'Fork', 'LastName'),
    (1, '857685', 'AccountNumber'),
    (2, 'anna', 'FirstName'),
    (2, '22', 'Amount'),
    (2, 'wad', 'PostalCode'),
    (2, 'two', 'LastName'),
    (1, '123', '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 sites:
loading Hold tight while we fetch your results