简体   繁体   English

在R,Microsoft SQL Server中执行SQL函数

[英]Execute SQL-functions in R, Microsoft SQL Server

I have a number of functions written on our Microsoft SQL servers. 我在Microsoft SQL服务器上编写了许多函数。

I can easily access and query all data normally, but I cannot execute functions on the server using RODBC . 我可以轻松地正常访问和查询所有数据,但是无法使用RODBC在服务器上执行功能。

How can I execute sql-functions using R? 如何使用R执行sql函数? Are there other packages that can do this? 还有其他软件包可以做到这一点吗?

Or do I need to switch strategies completely? 还是我需要完全改变策略?

Example: 例:

require(RODBC)
db <- odbcConnect("db")

df <- sqlQuery(channel = db, query = "USE [Prognosis] 
GO 
SELECT * FROM [dbo].[Functionname] ("information_variable")
GO" ) 

Error message:
"42000 102 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'GO'."                                                                                                               
[2] "[RODBC] ERROR: Could not SQLExecDirect 'USE... "

This turned out to work: 事实证明这可行:

df <- sqlQuery(channel = db, 
query = "SELECT * FROM [dbo].[Functionname] ("information_variable")" )

So I dropped USE [The_SQL_TABLE] and GO 所以我放弃了USE [The_SQL_TABLE]GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM