我正在尝试使用R将SQL Server中几个表的所有数据复制到硬盘驱动器上的几个CSV文件中。我想它将看起来像这样...
library(RODBC)
library(XLConnect)
dbhandle <- odbcDriverConnect('driver={SQL Server};server=ServerName;database=DB_Name;trusted_connection=true')
# something here...
write.csv(currTableDF,file=paste("C:/Users/file_Name.csv",sep=""),row.names=FALSE)
答案 0 :(得分:0)
这对我有用...
install.packages("RODBC")
install.packages("dplyr")
library("RODBC")
conn <- odbcDriverConnect('driver={SQL Server};server=ServerName;database=DB_Name;trusted_connection=true')
data <- sqlQuery(conn, "SELECT * FROM Your_Table;")
write.csv(data,file=paste("C:/Users/file_Name.csv",sep=""),row.names=FALSE)