views:

24

answers:

1

Hi, I got a problem transforming a table that looks like this

PropertyName | PropertyValue
---------------------------------
color    red
color    blue
size    big
size    small

into this:

Color  | Size
---------------------------------
red   big
red   small
blue   big
blue   small

How can I achieve this? Thanks in advance for any help.

+1  A: 

You want every permutation of colours and sizes?

SELECT color, size FROM 
(
select distinct  PropertyValue AS color
from YourTable
where PropertyName = 'color'
) T1
CROSS JOIN 
(
select distinct  PropertyValue AS size
from YourTable
where PropertyName = 'size'
) T2
Martin Smith
Okay, that`s a start. Thanks very much. But is there a way, to do it automatically for all PropertyNames and -Values? I mean without having to write a cross join for each propertyname?
tombom
Not in standard SQL. Can you tag your question with the RDBMS you are using.
Martin Smith
Then I guess I have to live with it. Thanks again.
tombom
@tombom - For SQL server you would need to use dynamic SQL to create a string similar to the above that you then execute.
Martin Smith