[R] A Problem of RODBC's sqlQuery

PHTsai pinghan.tsai at gmail.com
Fri Mar 16 23:03:47 CET 2012


Hi All,

I encounter a problem of losing control of SQL when I use sqlQuery function
to command SQL. My problem is like:

library(RODBC)

ch <- odbcConnect("ASQLTable")

sqlQuery(ch, paste("
create table #MyTest( MyTest1 int, MyTest2 int, MyTest3 int, MyTest4 int,
MyTest5 int)
"))

for (i in 2){

sqlQuery(ch, paste("

insert into #MyTest
                select
                                i*1, i*2, I*3, i*4, i*5 "))
}

For the sqlQuery in the for loop, the function doesn't know whether every
data is inserted into #MyTest. So, in the case that there are 10000 members
in #MyTest and using the For loop along with sqlQuery, it is very likely
that not all of the data are inserted into #MyTest because it is possible
that while the first sqlQuery is still running, the second sqlQuery also
starts and interrupts the first one.

Could someone help me with this problem?

Thanks a lot.


--
View this message in context: http://r.789695.n4.nabble.com/A-Problem-of-RODBC-s-sqlQuery-tp4479487p4479487.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list