【发布时间】:2014-05-29 13:30:45
【问题描述】:
我正在通过 RODBC 运行 SQL 查询。我有一个字段给我带来查询问题,标题为“1YearTotalSpend”。它是一个数字字段,在进行一些诊断后,我可以看到字段值的内容没有错误,它们是数字。
具体来说,我收到的错误是:"[RODBC] ERROR: Could not SQLExecDirect...
library(RODBC)
# This works fine, where "AnyOtherSpendField"
# is a field whose name doesn't start w/ a numeral.
df <- sqlQuery(handle, "select ID, FieldA, FieldB, FieldC
from Table.A
where Type not like 'NULL'
and Code like 'SUB'
and Status in ('100','440','222')
and AnyOtherSpendField > 0
order by AnyOtherSpendField desc ")
# however both of the two options below fail:
"...and 1YearTotalSpend > 0"
"...order by 1YearTotalSpend ")
鉴于我的其余代码都可以正常工作,我强烈怀疑该错误是因为字段以 1 开头,而不是“一”。显然,以数字开头的字段是糟糕的数据管理实践,而不是我自己做的。
【问题讨论】:
-
尝试用双引号 "1YearTotalSpend" 将 1YearTotalSpend 括起来。
-
@rontornambe 没用...
-
我没有看到您使用的是使用方括号作为分隔符的 SQL-Server。
标签: sql r sql-server-2008 field rodbc