INSERT語句涉及的所有表都選擇,更新,刪除,插入理所當然的。我正試圖執行一個程序並獲取該錯誤。「[RODBC]錯誤:無法SQLExecDirect的」,因爲內部程序
我用odbcDriverConnect
,因爲我猜任何連接參數將解決我的問題(我試過trusted_connection
和autocommit
)。
cc = odbcDriverConnect(connection = paste0('DRIVER={SQL Server};SERVER=localhost;DATABASE=XX;UID=user;PWD=pass;autocommit=True;trusted_connection=true'))
rst = sqlQuery(cc, 'exec dbo.usp_mm_xx')
print(rst)
[1] "[RODBC] ERROR: Could not SQLExecDirect 'exec dbo.usp_mm_xx'"
如果我退出程序insert
它運行正常。
當我嘗試運行insert
時,出現同樣的錯誤。
query=paste0('insert INTO dbo.X select * FROM dbo.Y a ',
'where not exists (select 1 from dbo.X b where a.c1=b.c1 and a.c2=b.c2)')
rst=sqlQuery(cc, query)
print(rst)
[1] "[RODBC] ERROR: Could not SQLExecDirect 'insert INTO dbo.X SELECT * FROM dbo.Y a where not exists (select 1 from dbo.X b where a.c1=b.c2 and a.c2=b.c2)'"
SQL語句在數據庫上運行正常,具有相同的用戶。
是'Excute'也就理所當然? – Sami
是,按照授予的程序執行。它在我退出插入時運行。 – xm1
在第一行有程序指令「Set nocount on」嗎?它應該有。 –