R to SQL server. Make a query joining a database table with a R dataframe -


i have odbc connection sql server database. r, want query table lots of data, want records match dataframe in r columns (inner join). linking odbc tables in ms access 2003 (linked tables "dbo_name") , doing relational queries, without downloading entire table. need reproduce process in r avoiding downloading entire table (avoid sqlfetch ()).

i have read information odbc, dbi, rsqlserver packages without success. there package or way fix this?

many thanks!

if can't write table database, there trick can use. make giant where statement. let's want join table table in database data.frame called a on column id. say:

ids <- paste0(a$id,collapse=',')  # if a$id character, you'll have surround in quotes: # ids <- paste0(paste0("'",a$id,"'"),collapse=',') dbgetquery(con, paste0('select * table id in (',paste(ids,collapse=','),')')) 

from comment, seems sql server has problem query of size. suspect may have "chunk" query smaller bits, , join them together. here example of splitting ids 1000 chunks, querying, , combining.

id.chunks <- split(a$ids,seq(1000)) result.list <- lapply(id.chunks, function(ids)                   dbgetquery(con,                              paste0('select * table id in (',ids,')'))) combined.resuls <- do.call(rbind,result.list) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -