2

I have written a query using PIVOT function.The db is on client side. When i am running the query it throws an error,

Incorrect syntax near 'PIVOT'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the SET COMPATIBILITY_LEVEL option of ALTER DATABASE.

After this I ran these two queries,

SELECT @@version;
SELECT compatibility_level FROM sys.databases WHERE name = 'db_name';

The output is

Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) 
Jun 17 2011 00:54:03 
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

and

80

I am not a db expert, But what I guess is they are using SQL server 2008 with compatibility mode of SQL server 2000 i.e 80 .Let me know if I am wrong. I do not think the Client will agree to change the compatibility level. So Is there any way to run a PIVOT query?

user3427540
  • 1,162
  • 1
  • 14
  • 30
  • Just use an alternative with `CASE ... WHEN ... THEN`. Google it, it is easy to do – cha Sep 16 '14 at 04:12
  • please post your query to suggest an alternative way to write the same.. as there can be many ways to improve the query.. – Deepshikha Sep 16 '14 at 04:23
  • Refer to [this Stackoverflow post](https://stackoverflow.com/questions/312861/pivot-using-sql-server-2000). It has some suggestions. Alternatively raise the compatibility level to 90 (SQL Server 2005), PIVOT/UNPIVOT was introduced in SQL Server 2005. – TT. Sep 16 '14 at 06:44

0 Answers0