Pivot table without aggregate function

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://stackoverflow.com/questions/8543218/display-cell-value-as-column-name-using-sql

Stack Overflow

Q&A for programmers

-- Pivot table without aggregate function
-- http://stackoverflow.com/questions/8543218/display-cell-value-as-column-name-using-sql

declare @test table(
   Name varchar(30) not null,
   Grade varchar(10) not null,
   Subject varchar(10) not null
)

insert into @test values('Ami', 'HD', 'Java')
insert into @test values('Ami', 'D', 'C++')
insert into @test values('Bec', 'D', 'Java')
insert into @test values('Bec', 'P', 'C++')

select Name, Max(case Subject when 'C++'  then Grade end) 'C++',
             Max(case Subject when 'Java' then Grade end) 'Java'
from @test
group by Name

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached