CREATE table #yourtable ([FormId] int, [Value] varchar(6)...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Home Improvement Meta

Q&A about the site for contractors and serious DIYers

CREATE table #yourtable
    ([FormId] int, [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([FormId], [Value], [ColumnName])
VALUES
    (1, 'John', 'FirstName'),
    (1, '2.4', 'Amount'),
    (1, 'ZH1E4A', 'PostalCode'),
    (1, 'Fork', 'LastName'),
    (1, '857685', 'AccountNumber'),
    (2, 'Bob', 'FirstName'),
    (2, '5.4', 'Amount'),
    (2, 'AH1E4A', 'PostalCode'),
    (2, 'Smith', 'LastName'),
    (2, '123456', 'AccountNumber')
;

select
    p.*
from #yourtable
pivot(
    max(value)
    for columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber)
) as p

Enter Parameters

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