rodbc

R Pass required variable from ODBC/HANA connection to sql statement

∥☆過路亽.° 提交于 2020-01-24 22:05:39
问题 I have a table I am trying to call with my usual method sql <- 'SELECT TOP 10 * FROM "_SYS_BIC"."data-path.self-service.DOIP/table_name"' df <- dbGetQuery(jdbcConnection, sql) and receive the error Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", : Unable to retrieve JDBC result set for SELECT TOP 10 * FROM "_SYS_BIC"."data-path.self-service.DOIP/table_name" (SAP DBTech JDBC: [2048]: column store error: search table error: [34023] Instantiation of calculation model

R RODBC putting list of numbers into an IN() statement

瘦欲@ 提交于 2020-01-23 00:47:01
问题 I've looked at the 'Pass R variable to RODBC's sqlQuery with multiple entries? ' already but can't seem to get it to work. I'm trying to do an sqlQuery() from R on a SQL Server 2008 R2 db. I'm trying to get a sample from a large db based on row numbers. First I created a list of random numbers: sampRowNum <- sample(seq(1,100000,1), 5000) Then I try to use those numbers in a query using: query1 <- sqlQuery(channel, paste("select * FROM db where row_id in (", sampRowNum,")", sep="")) I get just

R RODBC putting list of numbers into an IN() statement

旧城冷巷雨未停 提交于 2020-01-23 00:46:20
问题 I've looked at the 'Pass R variable to RODBC's sqlQuery with multiple entries? ' already but can't seem to get it to work. I'm trying to do an sqlQuery() from R on a SQL Server 2008 R2 db. I'm trying to get a sample from a large db based on row numbers. First I created a list of random numbers: sampRowNum <- sample(seq(1,100000,1), 5000) Then I try to use those numbers in a query using: query1 <- sqlQuery(channel, paste("select * FROM db where row_id in (", sampRowNum,")", sep="")) I get just

sqlFetch Table not found error

旧城冷巷雨未停 提交于 2020-01-16 19:23:30
问题 After I use cn<-odbcConnect(...) to connect to MS SQL Server. I can successfully get data using: tmp <- sqlQuery(cn, "select * from MyTable") But if I use tmp <- sqlFetch(cn,"MyTable") R would complain about "Error in odbcTableExists(channel, sqtable) : table not found on channel". Did I miss anything here? 回答1: Assuming you work on Windows OS. When you define your "dsn" in Control panel > Administrative tools > System and Security > Data Sources (ODBC), you have to select a database as well.

R Getting the number of rows which have been updated

血红的双手。 提交于 2020-01-16 01:15:52
问题 How can we get the number of rows affected by the executed UPDATE query? r <- sqlQuery(channel, 'UPDATE foo SET bar = 1') What I get (from a connection to a MS SQL Server DB) is just a character(0) ... 回答1: From the Microsoft Data Access SDK ODBC Help guide: SQLRowCount returns the number of rows affected by an UPDATE, INSERT, or DELETE statement; an SQL_ADD, SQL_UPDATE_BY_BOOKMARK, or SQL_DELETE_BY_BOOKMARK operation in SQLBulkOperations; or an SQL_UPDATE or SQL_DELETE operation in SQLSetPos

Automatic transfer data from the sql to R

自作多情 提交于 2020-01-15 09:24:09
问题 I get the data from the sql server to perform regression analysis, and then the regression results i return back to another sql table. library("RODBC") library(sqldf) dbHandle <- odbcDriverConnect("driver={SQL Server};server=MYSERVER;database=MYBASE;trusted_connection=true") sql <- "select Dt ,CustomerName ,ItemRelation ,SaleCount ,DocumentNum ,DocumentYear ,IsPromo from dbo.mytable" df <- sqlQuery(dbHandle, sql) reg=lm(SaleCount~IsPromo,data=df) #save to sql table sqlSave(dbHandle, as.data

Error when trying to connect R to PostgreSQL using RODBC

夙愿已清 提交于 2020-01-13 10:17:13
问题 I am trying to connect to R using RODBC. However, when I run ch <- odbcConnect("rails_dev", uid="skline", pwd="d0gsleep") I get this error: In odbcDriverConnect("DSN=rails_dev;UID=skline;PWD=d0gsleep") : [RODBC] ERROR: state IM002, code 0, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded Any thoughts? I am new to this and at a loss for what to do next... thank you so much in advance!' Note I am using Mac OSX 回答1: EDIT: The

Dynamic “string” in R

半城伤御伤魂 提交于 2020-01-08 18:03:19
问题 Simple question, but cannot find the answer. Instead of: Df <- sqlQuery(ch, "SELECT * FROM tblTest WHERE Id=25") I want a more dynamic piece of code. Something like: Id <- 25 Df <- sqlQuery(ch, c("SELECT * FROM tblTest WHERE Id=", Id)) But this is not correct. 回答1: We can use paste: Df <- sqlQuery(ch, paste("SELECT * FROM tblTest WHERE Id =", Id)) c concatenates into a vector, paste is for string concatenation. Or we can use sprintf: sprintf("SELECT * FROM tblTest WHERE Id = %s", Id) 回答2: If

How to use sqlSave function with existing table in R

我们两清 提交于 2020-01-05 02:03:53
问题 I can use sqlSave to create a new table and to append data to that table, but I want the tablet to have some additional columns (for instance, an "ID" autoincrementing column - I am manually adding these columns after creating the table and testing that I can save to it and append to it). As soon as I try to use sqlSave after adding those columns I get an error when trying to use sqlSave to append more data Error in odbcUpdate... missing columns in 'data' So I added an ID column to my data

Error with sqlSave

我们两清 提交于 2020-01-04 05:54:43
问题 I'm fighting with sqlSave to add my matrix B that looks like this: Noinscr 88877799 45645687 23523521 45454545 to an SQL table. so I run the following command: sqlSave(channel, b, "[testsFelix].[dbo].[TREB]", append = TRUE, rownames = FALSE, colnames = FALSE, safer = TRUE, fast = FALSE) and I get the following error: Erreur dans sqlSave(channel, b, "[testsFelix].[dbo].[TREB]", append = TRUE, : 42S01 2714 [Microsoft][SQL Server Native Client 10.0][SQL Server] There is already an object named