[R] RODBC looping sql script
Bart Joosen
bartjoosen at hotmail.com
Fri Feb 26 08:14:59 CET 2010
Hi,
You should use the paste command:
for (i in 1:length(vessel[,1])) {
query<-paste("Select * From vessel Where common.utility(", vessel[i,1],", ",
,vesselyear[i,2], ")", sep="")
final<-sqlQuery(channel,paste(query))
}
Bart
Jason Gasper wrote:
>
> Dear R users,
>
> I am querying an Oracle database using sqlQuery() from the RODBC
> package. What I would like to do is embed my R Sql query in a for loop.
> For example
> suppose the data.frame "vessel" contains two columns: vessel[,1]= vessel
> id and vessel[,2]=permit year
>
> I am using "vessel" as an input in a SQL based function that require
> inputs of permit year and vessel id as described below:
>
> query<-"Select * From vessel Where common.utility(vessel ID,vessel year)"
>
> final<-sqlQuery(channel,paste(query))
>
> Now suppose I want to loop through my vessel table such that the vessel
> ID and vessel year corresponds with i:
>
> for (i in 1:length(vessel[,1])) {
> query<-"Select * From vessel Where common.utility(vessel[i,1],vessel
> year[i,2])"
> "
> final<-sqlQuery(channel,paste(query))
>
> }
> Ignoring the fact I didn't include code to create and ever expanding
> final table for loop, does anyone know how to index inside the Where
> clause of a sql statement (i.e., common.utility(vessel[i,1],vessel
> year[i,2])?
>
>
>
>
>
> --
> Jason Gasper
> National Marine Fisheries Service
> Alaska Region, Sustainable Fisheries Division
> 709 W. 9th St. Juneau, Alaska 99801
> Juneau, Alaska 99801
>
> Phone 907-586-7237
> Fax 907-586-7249
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
View this message in context: http://n4.nabble.com/RODBC-looping-sql-script-tp1570038p1570237.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list