“to_char”不是可识别的内置函数名称

Aru*_*nam -8 sql sql-server date type-conversion to-char

    (to_char(sysdate,'YYYY')+least(sign((sysdate-to_date('01-Aug-'||
to_char(sysdate,'YYYY'),'DD-Mon-RRRR'))),0)) "AcYear"
Run Code Online (Sandbox Code Playgroud)

错误:

'to_char' is not a recognized built-in function name.
Run Code Online (Sandbox Code Playgroud)

我尝试将 to_char 和 to_date 更改为 CONVERT 但出现错误。

我期待 2016 年 AcYear

有人可以帮忙吗?

Gor*_*off 5

在 SQL Server 中,如果您想要八月的第一天,则使用datefromparts()

select datefromparts(year(getdate()), 8, 1)
Run Code Online (Sandbox Code Playgroud)

这适用于 SQL Server 2012+。早期版本需要稍微多一些的工作:

select cast(datename(year, getdate()) + '0801' as date)
Run Code Online (Sandbox Code Playgroud)