Q&A about the site for software engineers working on automated testing, continuous delivery, service integration and monitoring, and building SDLC infrastructure
CREATE table #yourtable ([Id] int, [Value] varchar(6), [ColumnName] varchar(13)) ; INSERT INTO #yourtable ([Id], [Value], [ColumnName]) VALUES (1, 'John', 'FirstName'), (2, '2.4', 'Amount'), (3, 'ZH1E4A', 'PostalCode'), (4, 'Fork', 'LastName'), (5, '857685', 'AccountNumber'), (6, '857685', 'AccountNumber') ; select Id, Firstname, Amount, PostalCode, LastName, AccountNumber from ( select Id, value, columnname from #yourtable ) d pivot ( count(columnname) for columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber) ) piv;