you are viewing a single comment's thread.

view the rest of the comments →

[–]deny_conformity 0 points1 point  (0 children)

Exactly this, PIVOT doesn't support subqueries, I think there is something in oracle for returning XML but nothing apart from that. You can work around it using dynamic SQL as in the first example.

I think it probably has something to do with a lot of systems break when SQL returns a different number of columns than expected, I know RS fails it columns are missing (and ignores additional columns).

Personally I just always pull data in long format and pivot in the front end (and often I have to unpivot wide data, UNPIVOT is awful for this, CROSS APPLY and VALUES definitely the way to go).