【问题标题】:SQL Server 2008 R2 - convert() works but cast() does not - any suggestions?SQL Server 2008 R2 - convert() 有效,但 cast() 无效 - 有什么建议吗?
【发布时间】:2017-07-28 16:06:08
【问题描述】:

请在将其标记为重复之前,我已多次阅读此帖子the first thing that always pops up in google,但我认为它不能解决我的问题。

在通过 ODBC 到 SQL Server 2008 R2 的传递查询中...

这确实有效:

 (SELECT x, convert(date, y) FROM so_q1);

但这不起作用:

 (SELECT x, (cast y as date) FROM so_q1);

知道为什么吗?

【问题讨论】:

  • (cast y as date)?你的意思是cast(y as date) - 如果不是,请分享错误详情。
  • @AlexK.- /snort - 谢谢 - 它不起作用,因为它的语法不正确。

标签: sql-server datetime sql-server-2008-r2


【解决方案1】:
(SELECT x, (cast y as date) FROM so_q1);-- does not work because it is the incorrect syntax.

(SELECT x, cast( y as date) FROM so_q1); --works just fine.

谢谢@AlexK

【讨论】:

    猜你喜欢
    • 2015-07-09
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多