-1
我在SQL服务器中有一个大表,并希望在日期使用WHERE子句导入到R中。从SQL服务器过滤并读取数据集到R
library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL Server};server=mysqlhost;database=mydbname;trusted_connection=true')
# Main table query works well
res <- sqlQuery(dbhandle, 'select * from Main')
# I would like to filter it by date column
res <- sqlQuery(dbhandle, 'select * from Main where Date > '2010-01-01'')
您可能遇到单引号问题。你必须逃避它们。您的查询没有任何问题@Prasanth – MaxPD
或在外部使用双引号:'“select * from Main where Date>'2010-01-01';'' – SymbolixAU
您可能还需要使用'[Date]' 。我相信日期是SQL中的保留字。 – Benjamin