Question
· Jan 22

Transform rows to colums or colums to rows

Hello guys,

I need to tranform columns into rows or rows into columns.

I'm using only SQL Cache.

The code:

SELECT
    codRepresentante
    ,vendasAbril
    ,vendasAgosto
FROM
    Ped.MetasRepresen
WHERE ano = 2024

The columns: 

Can you help me?

Thanks

Product version: Caché 2018.1
Discussion (1)1
Log in or sign up to continue

something like this ?

| COL    | VAL |
| ------ | --- |
| codRep |        401,       428,       428,       464,       472 |
|  Abril |     100000,    180000,    160000,         0,         0 |
| Agosto |     100000,    350000,    200000,     90000,         0 |

then this is the SQL statement
 

SELECT 'codRep' "COL", list($JUSTIFY(codRepresentante,10)) "VAL"
   FROM Ped.MetasRepresen where ano=2024
Union All
SELECT ' Abril', list($JUSTIFY(vendasAbril,10)) 
   FROM Ped.MetasRepresen where ano=2024
Union All
SELECT 'Agosto', list($JUSTIFY(vendasAgosto,10))
   FROM Ped.MetasRepresen where ano=2024