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


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])
    (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 =
  and a.columnname = 'Amount'
left join #yourtable pc
  on =
  and pc.columnname = 'PostalCode'
left join #yourtable ln
  on =
  and ln.columnname = 'LastName'
left join #yourtable an
  on =
  and an.columnname = 'AccountNumber'
where fn.columnname = 'Firstname'

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results