Script to create dynamic PIVOT queries in SQL Server
Pivoting is a common reporting requirement - data is stored in columns and you need to present it in rows. This was a nice feature that was added to SQL Server, but you don't always know all of the values you need to pivot on. This tip looks at how you can dynamically create the pivot command to handle these unknown values.
Top 5 hard-earned lessons of a DBAIn part one, read about ‘The Case of the Missing Index’ and learn from the experience of The DBA Team. Read now.