My Query

0

Please login or register to vote for this query.

(click on this box to dismiss)

Arqade

Q&A for passionate videogamers on all platforms

CREATE table #yourtable
([Id] int, [Eq_Id] nvarchar(12), [QuestionCd] varchar(2), [Value] varchar(6), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id],[Eq_Id],[QuestionCd], [Value], [ColumnName])
VALUES
    (1, 'Qwe111', 'Q1','John', 'Q1'),
    (2, 'Qwe111', 'Q2','2.4', 'Q2'),
    (3, 'Qwe111', 'Q3','ZH1E4A', 'Q3'),
    (4, 'Qwe111', 'Q4','Fork', 'Q4'),
    (5, 'Qwe111', 'Q5','857685', 'Q5')
;

select * from #yourtable;

select Eq_id, QuestionCd, Firstname, Amount, PostalCode, LastName, AccountNumber
from
(
  select value, columnname
  from #yourtable
) d
pivot
(
  max(value)
  for columnname in (Eq_id, QuestionCd, Firstname, Amount, PostalCode, LastName, AccountNumber)
) piv;

Enter Parameters

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