【问题标题】:'to_char' is not a recognized built-in function name'to_char' 不是可识别的内置函数名
【发布时间】:2017-10-19 15:47:43
【问题描述】:
    (to_char(sysdate,'YYYY')+least(sign((sysdate-to_date('01-Aug-'||
to_char(sysdate,'YYYY'),'DD-Mon-RRRR'))),0)) "AcYear"

错误:

'to_char' is not a recognized built-in function name.

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

我希望将 2016 年视为 AcYear

有人可以帮忙吗?

【问题讨论】:

  • 你确定你使用的是sql server吗? to_char 不是 sql server 中的函数。
  • Oracle 不是 SQL Server:功能各不相同。
  • 邮件看不懂怎么办?为什么在 SQL Server 中使用 Oracle/Postgres/Teradata 函数?至少,您应该编辑您的问题并提供示例数据和所需的结果。

标签: sql sql-server date type-conversion to-char


【解决方案1】:

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

select datefromparts(year(getdate()), 8, 1)

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

select cast(datename(year, getdate()) + '0801' as date)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-12
    • 2014-01-25
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多