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@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.

Reply via email to