I already read artfulsoftware and numerous topics here, but still can not understand why I can not make it work.
I have a very simple table (productProperties pp) with three columns:
prodName propName propValue
I want to request that it be presented as (for example)
prodName Color Weight Adhesive
nail1 black 1lbs 3m
nail2 silver 0.5lbs 3m
What I tried:
select
pp.prodName,
CASE pp.propName
WHEN 'Color' THEN pp.propValue
ELSE NULL
END as 'Color',
CASE pp.propName
WHEN 'Weight' THEN pp.propValue
ELSE NULL
END as 'Weight',
CASE pp.propName
WHEN 'Adhesive' THEN pp.propValue
ELSE NULL
END as 'Adhesive'
from
ProductsProperties as pp
group by pp.prodName;
I get all NULL except prodName
For instance:
prodName propName propValue
nail1 Color black
nail1 Adhesive 3M
nail2 Weight 1lbs
nail3 Color black
nail3 Adhesive 3M
nail5 Weight 1lbs
above query results:
prodName, Color, Weight, Adhesive
nail1, black, NULL, NULL
nail2, NULL, 1lbs, NULL
nail3, black, NULL, NULL
nail5, NULL, 1lbs, NULL
source
share