I am currently building a Shiny App that is based on a previous MS Access App. I need to replicate MS Access queries behind each Shiny app button in SQL Server. What is the best way to reuse the SQL syntax in MS Access in R (i.e., copy-paste the MS Access query directly in R)?
Indeed it appears that Access SQL is slightly different from SQL Server syntax and therefore I cannot simply do it using either DBI (dbGetQuery(), dbExecute(), dbSendQuery()) or dbplyr (sql()).
Here is an example with MS Access SQL syntax in R. ("100%" is left on purpose as a table name contains that string.)
UPDATE [table1]
INNER JOIN ([table2 100%]
INNER JOIN ([table3]
INNER JOIN table4
ON ([table3].[col1] = table4.[col1])
AND ([table3].col2 = table4.col2))
ON ([table2 100%].[col1] = [table3].[col1])
AND ([table2 100%].[col2] = [table3].[col2]))
ON [table1].col1 = [table3].col1
SET [table2 100%].[col2] = [table3]![col2]
WHERE ((([table3].[colY])<>0) AND (([table3].[colZ])=True));
Resulting in the following error message in R console :
Erreur : nanodbc/nanodbc.cpp:1617: 42000: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'INNER'. [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'table3'. [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
I also get : "The multi-part identifier … could not be bound in Join statements" when I tweak the query.
I set up my connection with :
con <- DBI::dbConnect(odbc::odbc(), driver = params.SQL.driver,
server = params.SQL.server, database = params.SQL.database,
encoding = params.SQL.encoding)
where params.SQL.server = "SQL Server"