Import multiline SQL query to single string

后端 未结 7 1024
傲寒
傲寒 2020-12-24 03:11

In R, how can I import the contents of a multiline text file (containing SQL) to a single string?

The sql.txt file looks like this:

SELECT TOP 100 
         


        
7条回答
  •  长情又很酷
    2020-12-24 03:44

    Here's the final version of what I'm using. Thanks Dirk.

    fileconn<-file("sql.txt","r")           
    sqlString<-readLines(fileconn)          
    sqlString<-paste(sqlString,collapse="")
    gsub("\t","", sqlString)
    library(RODBC)
    sqlconn<-odbcConnect("RPM")
    results<-sqlQuery(sqlconn,sqlString)
    library(qcc)
    tph <- qcc(results$tphmean[1:50], type="xbar.one", ylim=c(4000,12000), std.dev=600)
    close(fileconn)
    close(sqlconn)
    

提交回复
热议问题