Home > Mobile >  R - Concatenate SQL query string over multiple lines
R - Concatenate SQL query string over multiple lines

Time:01-25

I have a SQL query like this (example set, the query is actually much long and has multiple lines):

 Select entity, date, value 
 from Test.DB.View1
 where entity='abc'

I have a string ; entityvalue = 'abc' which is dynamic; changes based on user selection.

I would like to build a SQL query string that could incorporate entityvalue. For example:

paste("Select entity, date, value 
     from Test.DB.View1
     where entity='",entityvalue,"'",sep= " ")

The result from the above syntax becomes:

"Select entity, date, value \n         from Test.DB.View1\n         where entity='abc'"

What's the best way to avoid \n ?

CodePudding user response:

Separate the chunks to paste()

paste("Select entity, date, value",
     "from Test.DB.View1",
     "where entity='", entityvalue ,"'",sep= " ")
  • Related