我使用PIVOT函数编写了一个查询.db在客户端。当我运行查询时,它会抛出一个错误,
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.
在此之后我运行了这两个查询,
SELECT @@version;
SELECT compatibility_level FROM sys.databases WHERE name = 'db_name';
输出
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)
和
80
我不是数据库专家,但我猜他们正在使用SQL Server 2008与SQL Server 2000的兼容模式,即80.让我知道我是不是错了。我不认为客户会同意更改兼容级别。那么有没有办法运行PIVOT查询?