-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