0

Can someone please help me on this SQL query? I have a simple table that i need to pivot dynamically. the table consists of 3 fields as below.

Table
Part_no
Forecast_date
Forecast_qty

I would like to pivot the table on forecast_date so that I would see part_no as a row, forecast_date as the column heading and forecast_qty showing for each part/date combination. Is this possible?

[table contents]

Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39
MrGriff
  • 1
  • 1
  • It is possible, but what is the benefit? And, "it is possible" but not easy; you need to write code that will generate the code for the final query (this is what's called "dynamic SQL"). Dynamic SQL is generally not a good idea. If you need this for a report, then your reporting tool (not SQL) should be able to format your data that way. –  Nov 15 '16 at 14:02
  • 1
    @mathguy oracle doesnt have a dynamic pivot query like MSSQL ? – Juan Carlos Oropeza Nov 15 '16 at 14:07
  • 3
    Possible duplicate of [Dynamic pivot in oracle sql](http://stackoverflow.com/questions/15491661/dynamic-pivot-in-oracle-sql) – Juan Carlos Oropeza Nov 15 '16 at 14:10
  • 1
    @JuanCarlosOropeza - Quoting Tom Kyte (one of the real gurus in the Oracle world): *The short answer is "no"* (but see the long answers too). https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:5312784100346298561 –  Nov 15 '16 at 14:29

0 Answers0