CREATE table #yourtable ([value] int, [Alias] varchar(6),...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Bicycles Meta

Q&A about the site for people who build and repair bicycles, people who train cycling, or commute on bicycles

CREATE table #yourtable
    ([value] int, [Alias] varchar(6), [PKMatricula] varchar(13), [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([value], [Alias], [PKMatricula], [ColumnName])
VALUES
    (399, 'CCS', '4000', 'CCS'),
      (12, 'CBT', '4000', 'CBT'),
    (3, 'GOR', '4000', 'GOR'),
    (3, 'PRO', '4000', 'PRO'),
    (4, 'FAT', '5000', 'FAT')
;


select CCS, CBT, GOR, PRO, AnalisysAvgResult, Alias, PKMatricula
from
(
  select value, columnname
  from #yourtable
) d
pivot
(
  max(value)
  for columnname in (CCS, CBT, GOR, PRO, AnalisysAvgResult, Alias, PKMatricula)
) piv;

Enter Parameters

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