I'm using sqlQuery
for submitting an SQL query to an ODBC database, and try to retrieve the results
The following R script works
x = "'2013-12-19'"
sqlQuery(channel,paste("USE [JWFX]
DELETE FROM Currency$
WHERE [Date] = ",x,";
DELETE FROM MktIndex$
WHERE [Date] = ",x))
While the following R scritp, whose query properly works on SQL Server does not work when called in R:
sqlQuery(channel,
"USE [JWFX] GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1 GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1 GO
INSERT INTO Currency$
SELECT * FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database= C:/Users/admin/Dropbox/SQL Server/DatabaseInput/BBGdata.xlsx;','SELECT * FROM [Currency$] WHERE Date = 41627');")
and returns the following error:
[1] "42000 102 [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'GO'."
[2] "42000 102 [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'GO'."
[3] "[RODBC] ERROR: Could not SQLExecDirect 'USE [JWFX] GO\nEXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1 GO\nEXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1 GO\nINSERT INTO Currency$\nSELECT * FROM \nOPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database= C:/Users/admin/Dropbox/SQL Server/DatabaseInput/BBGdata.xlsx;','SELECT * FROM [Currency$] WHERE Date = 41627');'"
Why this happen? Any hint?
DELETE FROM Currency$ \n WHERE [Date] = ",x,";
Or just write the code in one line. – Martín Bel Dec 20 '13 at 20:01