【问题标题】:Unable to query SQL giving syntax error when converting DateTime转换 DateTime 时无法查询 SQL 给出语法错误
【发布时间】:2013-11-25 05:16:20
【问题描述】:

从 SQL Server Management Studio 进行此 SQL 查询时出现语法错误:

exec QData N'Name,Value,TimeStamp', 
     convert(datetime, '2013-11-25 03:25:02.000'), 
     N'IncludeBounding', N'Root.BDV101.Response.Value'

它说

关键字“convert”附近的语法不正确

有人知道为什么吗?

编辑:

如果我执行以下操作,它可以工作(没有错误)

Declare @time datetime
Set @time = '2013-11-25 03:25:02.000'
exec QData N'Name, Value, TimeStamp', @time, N'IncludeBounding', N'Root.BDV101.Response.Value'

【问题讨论】:

  • 您不能在EXEC 调用中使用函数和表达式 - 如果您需要进行一些转换等,您必须在调用之前进行并存储结果在变量中(如您的第二次尝试)

标签: sql sql-server datetime


【解决方案1】:

你可以像这样使用隐式转换:

exec QData N'Name,Value,TimeStamp','20131125 03:25:02.000',N'IncludeBounding',N'Root.BDV101.Response.Value'

【讨论】:

  • 它也不好用..没有错误出现,但没有数据显示
【解决方案2】:

请试一试,默认Datatime DAtatype不需要转换

exec QData N'Name,Value,TimeStamp','2013-11-25 03:25:02.000' ,N'IncludeBounding',N'Root.BDV101.Response.Value'

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    相关资源
    最近更新 更多