SQL Server 2014 Type DATE is not a defined system type

旧城冷巷雨未停 提交于 2019-12-11 17:05:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!