SQL Server ....not a recognized table hints option. .... ensure that your database compatilbility mode is set to 90."

arknldoa  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(123)

I'm getting frequent errors in code where it says
CustomerSales is not a recognized table hints option. If it is intended as a parameter to a table-valued function, ensure that your database compatibility mode is set to 90.

It's happened with several other tables eg Hires, CustomerNumbers, etc.

I came across this suggestion on google, but I'm not sure if it's the best thing to do? Or what may have caused the error in the first place?

Can anyone please advise what is likely to cause this type of error and the best solution?

ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = { 150 | 140 | 130 | 120 | 110 | 100 | 90 }

https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level?view=sql-server-ver15

An example of the code I get the error with is this:

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
rseugnpd

rseugnpd1#

Check the COMPATIBILITY_LEVEL and set it to 120; it works for me.

SELECT  name, compatibility_level
FROM    sys.databases
WHERE   name LIKE '%DBName%';

ALTER   DATABASE [DBName] 
SET     COMPATIBILITY_LEVEL = 120

相关问题