Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
djorre
Yak Posting Veteran
94 Posts |
Posted - 2009-06-11 : 08:24:02
|
Hi Friends,In order to create reports out of an event logging, I need to crosstab a log-table. The parameter names and values that are logged (with a certain timestamp) in the logtable then appair in the report in colums (grouped per timestamp), and the timestamps become unique rows.The problem is, that there can be a parameter added or deleted. So I can not make it with select max case, bevause then the number of colums is fixed. and the pivot function syntax is as I found quote: SELECT *FROM #temp123PIVOT( SUM(VaribleValue) FOR [Variable] IN ([Sales],[Expenses],[Taxes],[Profit]))AS p
So with hard coded Colums. It this possible to say quote: SELECT *FROM #temp123PIVOT( SUM(VaribleValue) FOR [Variable] IN (select parameters from logtable group by parameters))AS p
Does that work I could not test it yet? Or any suggestions ?Thank in advance,Joris |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
djorre
Yak Posting Veteran
94 Posts |
Posted - 2009-06-11 : 08:46:54
|
| Thanks! A new world has been opened to me : ) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-11 : 11:25:41
|
| also seehttp://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx |
 |
|
|
|
|
|