[英]Eomonth function on SQL Server 2014
EOMONTH()
was introduced in SQL Server 2012. EOMONTH()
是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). 我怀疑数据库的兼容性级别设置为低于该级别 (或者您实际上不在SQL Server 2014上)。
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = 120 -- 120 == SQL Server 2014
To determine your SQL Server version run: 要确定您的SQL Server版本,请运行:
SELECT @@VERSION
An alternative way of calculating EOMONTH is: 计算EOMONTH的另一种方法是:
DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @Date) + 1, 0))
EOMONTH() returns a date type EOMONTH()返回日期类型
REPLACE ( string_expression , string_pattern , string_replacement ) 替换 (string_expression,string_pattern,string_replacement)
REPLACE ( EOMONTH( cast(@variable as date) ) '-','.')
You are attempting an implicit conversion from date to string, and it seems you are assuming that a date data type actually contains a dash, which isn't true. 您正在尝试从日期到字符串的隐式转换,并且似乎您假设一个日期数据类型实际上包含一个破折号,但这是不正确的。 Just use format to the desired output. 只需将格式用于所需的输出即可。 No need for replace and use a set of DATEADD()
functions to substitute for EOMONTH()
无需替换并使用一组DATEADD()
函数来替换EOMONTH()
select format(dateadd(day,-1,dateadd(month, datediff(month,0, getDate()), 0)),'yyyy.MM.dd')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.