I am trying to extract data by using select statement of SQL from dataframe. below is the code and requirement.
select_df1 <- sqldf("select * from fields_tb where formname = "fetched_form_name"")
here fetched_form_name is a string variable which holds value to searched. this variable is defined in for loop and the value of this variable is changing upon ever loop. in each pass of loop different value should be fetched from select statement.
I am not sure how to use this variable in select statement in R studio. Please help.
If I understand you correctly, you can use the paste0() function to build your select statement. I added an unnecessary print() statement just to display the result of the paste0().
fetched_form_name <- "Form1"
SelectStatement <- paste0('select * from fields_tb where formname = "', fetched_form_name, '"')
print(SelectStatement)
[1] "select * from fields_tb where formname = \"Form1\""
select_df1 <- sqldf(SelectStatement)