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)

Ask Ubuntu Meta

Q&A about the site for Ubuntu users and developers

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, 'John2', 'FirstName'),
    (2, '88', 'Amount'),
    (2, '88', 'PostalCode'),
    (2, '88', 'LastName'),
    (2, '88', 'AccountNumber')
;


select fn.value as FirstName,
  a.value as Amount,
  pc.value as PostalCode,
  ln.value as LastName,
  an.value as AccountNumber
from #yourtable fn
left join #yourtable a
  on fn.id = a.id
  and a.columnname = 'Amount'
left join #yourtable pc
  on fn.id = pc.id
  and pc.columnname = 'PostalCode'
left join #yourtable ln
  on fn.id = ln.id
  and ln.columnname = 'LastName'
left join #yourtable an
  on fn.id = an.id
  and an.columnname = 'AccountNumber'
where fn.columnname = 'Firstname'

Enter Parameters

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