【发布时间】:2017-09-22 16:32:58
【问题描述】:
我正在使用 R/Shiny 中的 inputDateRange() 构建 SQL 查询语句。我的问题是处理各种字符串以将日期包含在 SQL 的 WHERE 条件中:
这是我的代码:
t.query <- paste0("Select [sensor_name], [temperature] from [dbo].
[temperature_sensor] where network_id = '24162' and date > "
, sQuote(format(input$my.dateRange[1], format="%d-%m-%Y"))
, " and date < "
, sQuote(format(input$my.dateRange[2], format="%d-%m-%Y"))
)
现在语句以单引号结束,我收到以下错误:
42000 102 [Microsoft][ODBC Driver 13 for SQL Server][SQL 服务器]'''附近的语法不正确。 [RODBC] 错误:不能 SQLExecDirect '选择 [sensor_name], [temperature] from [dbo].[temperature_sensor] 其中 network_id = '24162' 和日期 > '18-09-2017' 和日期
我需要用 " 关闭字符串,因为我在 "select .... 中启动它,我尝试显式添加 """ 或 dQuote("") 来连接 ",但我仍然遇到错误。
任何建议都非常感谢?
【问题讨论】:
标签: r string shiny double-quotes single-quotes