Sorry, I am afraid that I not able to produce a fully reproducible example, because I cannot provide public access to the SQL server. I can share some code snippets only.
On the other hand, the I was choosing the glue_sql() because it does the quotation automatically after identifying the SQL dialect based on the connection object (.con). But it looks that the SQL dialect was not recognized correctly.
According to the issue #120, the quoting is done by the DBI::dbQuoteString().
So, I have to continue my investigation with DBI. But if you know how to overwrite the SQL dialect and/or the quotation character in the DBI::dbQuoteString(), please share your solutions.
By the way I am using the following odbc connector:
con <-
dbConnect(odbc(),
# Microsoft ODBC Driver for SQL Server on Windows
driver = "SQL Server",
...)
SELECT "sepal_width" FROM "iris" WHERE "iris".sepal_length > 2 AND "iris".species = 'setosa'
This is a perfect SQL server call that was adapted from glue_sql example
var <- "sepal_width"
tbl <- "iris"
num <- 2
val <- "setosa"
glue_sql("
SELECT {`var`}
FROM {`tbl`}
WHERE {`tbl`}.sepal_length > {num}
AND {`tbl`}.species = {val}
", .con = con2)
I only made a change to create con2 from ODBC connection to SQL Server, but your way of creating connection fine as well.
Is it possible that you are using val instead of var, when naming columns?