Incorrect syntax near ‘PIVOT’

This is caused by the database compatibility level being lower than what’s needed. Level 80 is SQL 2000, Level 90 is SQL 2005. Pivot needs SQL 2005, so :

EXEC sp_dbcmptlevel 'mydb', 90

PIVOT is a very neat little operation that can be used to denormalize data, used by statistics software for example. More : http://geekswithblogs.net/lorint/archive/2006/08/04/87166.aspx

Advertisements