Search code examples
sqlsql-serversql-server-2014

Eomonth function on SQL Server 2014


I am getting an error on this function, even it is defined. What could cause this problem?

enter image description here


Solution

  • EOMONTH() was introduced in SQL Server 2012.

    I suspect the Compatibilty level of your database is set below that (or you are in fact not on SQL Server 2014).

    ALTER DATABASE database_name   
    SET COMPATIBILITY_LEVEL = 120   -- 120 == SQL Server 2014
    

    To determine your SQL Server version run:

    SELECT @@VERSION
    

    An alternative way of calculating EOMONTH is:

    DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @Date) + 1, 0))