CREATE table #yourtable ([Id] int, [Value] varchar(30), [...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

CREATE table #yourtable
    ([Id] int, [Value] varchar(30), [ColumnName] varchar(30))
;
    
INSERT INTO #yourtable
    ([Id], [Value], [ColumnName])
VALUES
(24025,	'LA',	'Granos'),
(19529,	'LA',	'Halves'),
(97277,	'LA',	'Halves and Pieces'),
(69733,	'LA',	'Large Pieces'),
(149830,	'LA',	'Medium Pieces'),
(86502,	'LA',	'Nibs'),
(17957,	'LA',	'Pieces'),
(2550,	'LA',	'Scalper'),
(77883,	'LA',	'Small Pieces'),
(78107,	'LA',	'Topping'),
(23615,	'LLA',	'Granos'),
(26553,	'LLA',	'Halves'),
(181468,	'LLA',	'Halves and Pieces'),
(167093,	'LLA',	'Large Pieces'),
(249107,	'LLA',	'Medium Pieces'),
(156835,	'LLA',	'Nibs'),
(26784,	'LLA',	'Pieces'),
(3050,	'LLA',	'Rework'),
(4800,	'LLA',	'Scalper'),
(155883,	'LLA',	'Small Pieces'),
(51441,	'LLA',	'Topping'),
(116022,	'LT',	'Granos'),
(139598,	'LT',	'Halves'),
(328959,	'LT',	'Halves and Pieces'),
(1564549,	'LT',	'Large Pieces'),
(725342,	'LT',	'Medium Pieces'),
(159385,	'LT',	'Nibs'),
(161660,	'LT',	'Pieces'),
(1461,	'LT',	'Rework'),
(135865,	'LT',	'Scalper'),
(1386642,	'LT',	'Small Pieces'),
(84921,	'LT',	'Topping'),
(1400,	'OIL STOCK',	'Halves and Pieces'),
(233,	'Oil Stock',	'Large Pieces'),
(2505,	'OIL STOCK',	'Medium Pieces'),
(1000,	'OIL STOCK',	'Nibs'),
(1178,	'PRE',	'Halves'),
(1686,	'PRE',	'Halves and Pieces'),
(18827,	'PRE',	'Large Pieces'),
(3325,	'PRE',	'Medium Pieces'),
(10000,	'SHELL',	'Rework'),
(35110,	'SHELL',	'Scalper')
;


select
  max(case when columnname = 'Halves' then value end) Firstname,
  max(case when columnname = 'Granos' then value end) Amount,
  max(case when columnname = 'Small Peices' then value end) PostalCode,
  max(case when columnname = 'Nibs' then value end) LastName,
  max(case when columnname = 'Scalper' then value end) AccountNumber
from #yourtable

Enter Parameters

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