I've got a stored procedure that generates a Pivot table as a result set based on certain parameters I pass to the SP. However, I would like to create a view of that data without having to define the column headers for the pivot columns.
My concept would be to include a WHERE clause in the subquery that only pulls data from the previous 30 days, something like:
SELECT Entity_ID, docDate, [Gas]
FROM myTable WHERE docDate >= '2015-03-01'
) as T
) as pvt
without the IN clause in the PIVOT clause. And the output would look something like:
Entity_ID [2015-03-01] [2015-03-02] [2015-03-03] ... [2015-03-19]
1 25 27 24 30
2 100 95 117 110