Can you help me in the following scenario with the SQL without UDF's.
jan feb mar apr may ......... dec
100 200 300 400 500 1200
Thank you for your time on this.
min(case when sales_month = 'jan' then sales_amnt else 0 end) as jan,
min(case when sales_month = 'feb' then sales_amnt else 0 end) as feb,
min(case when sales_month = 'dec' then sales_amnt else 0 end) as "dec"
In case you might have multiple entries per month in your table or values that can be greater or smaller than zero at the same time you can take Dieters code and replace the "min" into "sum"
Since TD14.10 there's a TD_UNPIVOT function:
Please check the blog with detail steps.
This will be very useful in case you are looking for a SQL solution for transpose with huge data in the table, where simple logic like "CASE WHEN.." blocks won't work, which may be perfect for few limited records.
This will just give you additional columns with no change in row count. I presume the person wants all the relevant rows to be transposed into a single row.