I have tried the readLines and the read.csv functions but then don't work.
Here is the contents of the my_script.sql file:
SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate >= '1-july-1993' and it is saved on my Desktop.
Now I want to run this query from my R script. Here is what I have:
conn = connectDb() fileName <- "C:\\Users\\me\\Desktop\\my_script.sql" query <- readChar(fileName, file.info(fileName)$size) query <- gsub("\r", " ", query) query <- gsub("\n", " ", query) query <- gsub("", " ", query) recordSet <- dbSendQuery(conn, query) rate <- fetch(recordSet, n = -1) print(rate) disconnectDb(conn) And I am not getting anything back in this case. What can I try?
dbSendQuery(conn, "SELECT Emp..."), are any rows returned there? Are you confident that this is a problem with the read-from-file part and not a data-is-not-present problem?.sqlfile.paste(readLines(...), collapse = " ")with the same success. Since a.sqlfile is merely a text file with a different file extension, there's nothing cosmic. Is it something to do with your use ofqueryversusquery2? You don't show how you got to that second variable.readLines(..., encoding="UTF-8")? You may also want to look aticonv().