sqlQuery
提交一個SQL查詢到ODBC數據庫,並嘗試檢索結果
查詢SQL數據庫時
下列R-腳本工作
x = "'2013-12-19'"
sqlQuery(channel,paste("USE [JWFX]
DELETE FROM Currency$
WHERE [Date] = ",x,";
DELETE FROM MktIndex$
WHERE [Date] = ",x))
雖然下列R- scritp,其查詢正確適用於SQL中的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');")
,並返回以下錯誤:
[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');'"
爲什麼會發生這種情況?任何提示?
RODBC不太可能支持複雜的東西一樣那。我只會依賴基礎知識。 – joran
@joran:我懷疑這與R有什麼關係。它可能是SQL Server和/或Excel ODBC驅動程序的限制。 –
這就是我的意思,但我不清楚RODBC和驅動程序本身之間的區別。 – joran