CREATE table #yourtable ([Id] int, [Value] int, [ColumnNa...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Coffee Meta

Q&A about the site for people interested in all aspects of producing and consuming coffee

CREATE table #yourtable
    ([Id] int, [Value] int, [ColumnName] varchar(13))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
    (1, 30, 'first'),
    (2, 1393, 'second'),
    (3, 2.25, 'third'),
    (4, 110, 'fourth') 
;


select first, second, third, fourth ,fourth-first as calculations 
from
(
  select value, columnname
  from #yourtable
) d
pivot
(
  max(value)
  for columnname in (first, second, third, fourth )
) piv;

Enter Parameters

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