title: Teradata : Stored Procedure : parameter column name
body: <p>I'm looking for help with a stored procedure in teradata.  I want to update a whole table and for this I'm trying to use a for loop cursor. the problem is that my update is defined via column names passing through parameters to the SP.</p>
  
  <p>I've seen it can be possible to use dynamic sql to do that but I haven't found any information on the subject concerning for loop cursor and dynamic sql. Is it possible with FOR LOOP CURSOR ? 
  I've tried to do only the select and calculs with dynamic sql, it works fine but then the problem is to update the table from the cursor on the select. In this case how to update a table from my cursor?</p>
  
  <p>I let you show my code.</p>
  
  <p>loop cursor :</p>
  
  <pre><code>REPLACE PROCEDURE [database].calDELAI
   (
       IN dateDebut   VARCHAR(30),
       IN dateFin   VARCHAR(30),
       IN delay VARCHAR(30)
   )
   BEGIN
         DECLARE DATE_DEBUT_COLONNE VARCHAR(64);
         DECLARE DATE_FIN_COLONNE VARCHAR(64);
  
         SET DATE_DEBUT_COLONNE=dateDebut;
         SET DATE_FIN_COLONNE=dateFin;
  
         FOR for_loop_update AS cur_select_set CURSOR FOR
                         SELECT 
                         TMP.DATE_FIN_COLONNE-TMP.DATE_DEBUT_COLONNE
                         FROM [database].ORD_T_DETL_ORDR_DELAI AS TMP
                         /* the select is more complicated but here is the spirit of it.*/
          DO
                         IF (delay='DELAI1') THEN SET DELAI1=NB_JR_OUVRABLE;
                         END IF;
         END FOR ;
   END ;
  </code></pre>
  
  <p>The errors given by teradata are :</p>
  
  <pre><code>    SPL1027:E, Missing/Invalid SQL statement'E(3810):Column/Parameter '[database].TMP.DATE_FIN_COLONNE' does not exist.'.
      SPL2001:E, Undefined symbol 'DELAI1'.
      SPL2001:E, Undefined symbol 'NB_JR_OUVRABLE'.
  </code></pre>
  
  <p>Thanks in advance for your replies and your help.</p>