Unanswered: Query to use Column values and column names
I am new to this forum and this is my first post.
I want to use the column values as column names.Below is the sample table and expected output.
I am using Aqua data studio version 4.5.2 and database is Sybase ASE 11.
Please help me with the query for the below.
Thank you in advance.
Country Product Amount
US OTC 10
US OTC 20
US FX 50
LN FX 30
LN FX 40
Expected output table
Country OTC FX
US 30 50
LN 70 0
You can maybe have this by :
select "Country", "Product", "Amount", 0 order_indic
select Country, convert(varchar,Product), convert(varchar, Amount), 1 order_indic
order by order_indic
The column names (OTC ,FX) can we get them dynamically rather then hardcoding them in the query.
Say for example , tomorrow there is one more product added FXO ,we should be able to get one more column "FXO" without changing the query.