CREATE table #yourtable ([Name] varchar(100), [occupation...

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

CREATE table #yourtable
([Name] varchar(100), [occupation] varchar(100))
;
    
INSERT INTO #yourtable
    ([Name], [occupation])
VALUES
    ('james', 'D'),
    ('Mary', 'A'),
    ('Robert', 'A'),
    ('Patrica', 'S'),
    ('John', 'P'),
    ('Jennifer','D'),
    ('Micheal','D'),
    ('linda','S'),
    ('david','P'),
    ('elizabeth','A'),
    ('William','D'),
    ('Barbara','P'),
    ('Richard','P'),
    ('Susan','P'),
    ('Joseph','S'),
    ('jessica','S'),
    ('thomas','P'),
    ('Sarah','D')
;


select *
from
(
  select *
  from #yourtable
) as d
pivot
(
  max(name)
  for occupation in (D,A,S,P)
) piv;

Enter Parameters

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