title: using an R list in WHERE clause of SQL query
body: <p>I am attempting to use a list of values from a table in the WHERE clause of a SQL query. Specifically, if pat_ids is my list, e.g. pat_list= c('abc','xyz','123'), I attempt to run (in R)</p>
  
  <pre><code>library('RODBC')
  edw = odbcConnect('Teradata')
  allVisit = sqlQuery(
      edw,
      "SELECT
          fe.*
          FROM edwcdm_pc_views.fact_encounter AS fe
              JOIN edwcdm_pc_views.fact_diagnosis AS fd on   fe.encounter_sk = fd.encounter_sk
          WHERE
          fe.Patient_Sk in paste("(",paste(pat_ids,collapse=","),")",sep="")
  ")
  </code></pre>
  
  <p>I get the error "unexpected string constant in WHERE fe.Patient_Sk</p>
  
  <p>What I am doing wrong exactly? Am I not reformatting the list correctly as a string for the SQL WHERE clause, or is there a more fundamental problem with the syntax of trying to use an R object as a SQL query term?</p>