问题
I am using the below query in the stored procedure
SELECT @ICOUNT = COUNT(*)
FROM MESSAGES
WHERE CAST(CREATEDDATE AS DATE) >= CAST(@STARTDATE AS DATE)
AND CAST(CREATEDDATE AS DATE) <= CAST(@ENDDATE AS DATE);
Its working correctly in Sql Server 2008, Where as in Sql Server 2014 I'm facing the below error:
Type DATE is not a defined system type.
回答1:
If the compatibility level is 90, it means you are not working with SQL Server 2014, since it does not support this compatibility level (lowest supported is 100).
If you are working with 2012 (which is the highest version supporting compatibility level 90), you should change the compatibility level to 110. For 2008 / 2008 r2 version, the maximum compatibility level is 100.
Change the compatibility level using alter database:
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = 110 -- or 100 for 2008 versions.
来源:https://stackoverflow.com/questions/54645938/sql-server-2014-type-date-is-not-a-defined-system-type