title: Teradata stored procedure with dynamic parameters called from R script
body: <p>I need to extract some data from Teradata to process in R.  I have around 84 Dep/sec keys with most of them having a different time span so my thought was to create a stored procedure in Teradata that will accept the Dep, Sec and Dates as parameters. I could then loop over the list in R calling the SP each time to create my data set.</p>
  
  <p>The SP I have created to test this idea is a very simple one but I can't get it to work.</p>
  
  <pre><code>CREATE PROCEDURE procTest4 (IntN integer)
  BEGIN
  CALL DBC.SysExecSQL('SELECT top' || IntN || '*
  from TableName');
  END;
  </code></pre>
  
  <p>Teradata does create the SP but I don't know how to execute it and pass the paramters to it.  When I try:
      Call procText4(10)
  I get the following error:</p>
  
  <p>5568: SQL statement is not supported within a stored procedure. </p>
  
  <p>The only other option for me is to create the SQL string in R and then run it from there but there is multiple passes of SQL which create volatile tables and the RODBC package doesn't seem to like them, plus it's a very messy way of doing it.</p>
  
  <p>Any help is much appreciated.</p>