title: Why will WHERE statement not work in sqlQuery in RODBC?
body: <p>We keep all our laboratory data in a Sybase database. When I want to do data manipulation and analysis I read the data into R with RODBC.</p>
  
  <pre><code>library(RODBC)
  channellab &lt;- odbcConnect("Labdata")
  indivs &lt;-sqlQuery(channellab,'SELECT * from CGS.Specimen')
  </code></pre>
  
  <p>So far so good, except that CGS.Specimen is a table for our entire lab holdings. There are almost 40000 specimens (rows) with 66 variables. It takes an unnecessary amount of time to read especially when I am only interested in the holdings of one study which has about 1000 specimens. The obvious way to fix it would be   </p>
  
  <pre><code>indivs &lt;-sqlQuery(channellab,'SELECT * from CGS.Specimen WHERE StudyCode="RP"')  
  </code></pre>
  
  <p>But when I run that I get </p>
  
  <blockquote>
    <p>[1] "42S22 -143 [Sybase][ODBC Driver][Adaptive Server Anywhere]Column not found: Column 'RP' not found" "[RODBC] ERROR: Could not SQLExecDirect 'SELECT * from CGS.Specimen WHERE StudyCode=\"RP\"'"   </p>
  </blockquote>
  
  <p>I have played with quotation marks and I have played with escape slashes but alas I have gotten nowhere. </p>
  
  <p>for instance  </p>
  
  <pre><code>indivs &lt;-sqlQuery(channellab,'SELECT * from CGS.Specimen WHERE StudyCode= 'RP'  ')
  </code></pre>
  
  <p>Error: unexpected symbol in "indivs &lt;-sqlQuery(channellab,'SELECT * from CGS.Specimen WHERE StudyCode= 'RP"</p>
  
  <pre><code>indivs &lt;-sqlQuery(channellab,"SELECT * from CGS.Specimen WHERE StudyCode= 'RP'  ")
  </code></pre>
  
  <p>Error in .Call(C_RODBCFetchRows, attr(channel, "handle_ptr"), max, buffsize,  : 
    negative length vectors are not allowed</p>
  
  <p>What do you suggest?</p>