Getting SQL stored procedure results into data.frame format using RODBC

点点圈 提交于 2019-12-04 03:55:41

问题


I am using the RODBC package to query for results in my SQL server. I have a certain stored procedure written that, when executed in my SQL Server Mgmt. studio (for example), returns a table. However, when I run the query through R, it returns character(0)

# Execute command...
sqlQuery(production,"exec port.tdp_RISK2_ModelRunCompare @ModelRunId1 = 399")

Weird thing is... when I do something like...

sqlQuery(production,"exec sp_who")

I get a table of results...

Help?


回答1:


I had the same problem.

You can try using:

set nocount on

in the MS SQL Server stored procedure so it will return just a dataset.

Regards,




回答2:


Try this:

sqlQuery(production,"exec port.tdp_RISK2_ModelRunCompare @ModelRunId1 = 399", errors=FALSE)



回答3:


Also try writing to a new data frame. I kept getting character(0) when I tried to overwrite an existing data frame with the sqlQuery function.



来源:https://stackoverflow.com/questions/8450832/getting-sql-stored-procedure-results-into-data-frame-format-using-rodbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!