views:

37

answers:

2

Hi I would like to rotate a full table:

LANGUAGE litAccept litDelete litErrorMsg  ..............
-------------------------------------------------
SPANISH  Accept    Delete    Error has ocurred
ENGLISH  Aceptar   Borrar    Ha ocurrido un error
.....

into something like this:

LANGUAGE     ENGLISH   SPANISH
---------------------------------------
litAccept    Accept    Aceptar    
litDelete    Aceptar   Borrar    
litErrorMsg  Error..   Ha ocurridO..
...

I see with PIVOT you can rotate a table, but I don't know who do this!

Please help, thanks

+1  A: 

http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx

Pivot can't do 'dynamic' so you'll have to use this method

adolf garlic
+1  A: 

Wow I have done it!!

Now I understand how it works PIVOT. I tried to rotate the entire table at once with dynamic SQL and there is no way to fit it in the syntax of pivot. The rotation must be done column by column (PIVOT) or line by line (UNPIVOT) inserting them in a temporally table to get the full transposing at the end.

I think this is the way for me.. but maybe it can be done in single query?? (UNION ALL ins't valid, you know ;P)

Next day I will write the solution I found.

Thanks!

Diego
You should be able to use pivot and unpivot in a single query rather than creating a temp table with the output of the unpivot becoming the input to the pivot.
Martin Smith
How can you do it if the number of rows and columns are dynamic?
Diego