October 24, 2013 at 8:44 am
Hi I have the following pivot table query that is working fine for static items list. But how can I build this query to do pivot for dynamic values for the column item(items could be 1,58).
Select HomeId, bed,chair, tables, radio
FROM
(
select * from houseitems
) As Temp
PIVOT
(
max([value])
FOR [item] In([bed], [chair], [tables], [radio])
) As pt
The above query will display cost of all items of one home as one single row.
Thanks.
October 24, 2013 at 9:58 am
In my opinion, cross tabs are a lot easier to do dynamic pivoting. for information on this, check the following article: http://www.sqlservercentral.com/articles/Crosstab/65048/
October 25, 2013 at 4:04 am
If you need dynamic number of columns, the only way I know to do it is with dynamic sql.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply