SQL Select Statement help

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.

Thanks in advance!

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)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.