我在代码中经常出现错误
CustomerSales 不是可识别的表提示选项。如果要将其用作表值函数的参数,请确保将数据库兼容性模式设置为 90。
其他几个表也发生过这种情况,例如 Hires、CustomerNumbers 等。
我在谷歌上发现了这个建议,但我不确定这是否是最好的做法?或者首先是什么导致了错误?
任何人都可以建议可能导致此类错误的原因以及最佳解决方案吗?
ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = { 150 | 140 | 130 | 120 | 110 | 100 | 90 }
我收到错误的代码示例如下:
WITH CustomerAges AS
(
SELECT
P.FirstName, P.LastName,
FLOOR (DATEDIFF(DAY, PD.BirthDate, GETDATE()) / 365.25) AS AGE
FROM
Sales.vPersonDemographics PD
INNER JOIN
Person.Person P ON P.BusinessEntityID = PD.BusinessEntityID
)
SELECT
*,
CASE
WHEN Age IS NULL THEN 'Unknown Age'
WHEN Age BETWEEN 0 and 17 THEN 'Under 18'
WHEN Age BETWEEN 18 and 24 THEN '18 - 24'
WHEN Age BETWEEN 25 and 34 THEN '25 - 34'
WHEN Age BETWEEN 35 and 49 THEN '35 - 49'
WHEN Age BETWEEN 50 and 64 THEN '50 - 64'
ELSE 'Over 65'
END AS AgeRange
FROM
CustomerAges
检查 COMPATIBILITY_LEVEL 并将其设置为 120,它对我有用
选择名称、兼容性级别 来自系统数据库 WHERE name LIKE '%DBName%';
更改数据库 [DBName] 设置 COMPATIBILITY_LEVEL = 120