title: Teradata Stored Procedure variables
body: <p>I'm trying to create a stored procedure to create all possible combination of a table with itself. For now, I got this code, but it produces the following error:</p>
  
  <blockquote>
    <p>Syntax error: expected something between the word 'A' and the integer '2'</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>CREATE MULTISET TABLE PRUEBA
  (
      CAMPO VARCHAR(10)
  );
  
  INSERT INTO PRUEBA VALUES('A');
  INSERT INTO PRUEBA VALUES('B');
  INSERT INTO PRUEBA VALUES('C');
  
  REPLACE PROCEDURE TEST()
  
  BEGIN
     DECLARE a VARCHAR(255);
     DECLARE b VARCHAR(225);
     DECLARE qry VARCHAR(255);
     DECLARE i INT;
     DECLARE n INT;
  
     SET a = 'SELECT * FROM PRUEBA A1 ';
     SET b = ' WHERE ';
     SET n = 3;
     SET i = 1;
  
     WHILE i &lt; n DO
        BEGIN
           CASE i
           WHEN 1 THEN
              SET qry = a;
           WHEN 2 THEN
              SET a = a || 'CROSS JOIN PRUEBA A' || i ; -- Error in this part.
              SET b = b || 'A' || (i-1) || '.CAMPO &lt; A' || i || '.CAMPO';
              SET qry = a || b;
           ELSE
              SET a = a || 'CROSS JOIN PRUEBA A' || i ;
              SET b = b || 'AND A' || (i-1) || '.CAMPO &lt; A' || i || '.CAMPO';
              SET qry = a || b;
           END CASE;
           SET i = i + 1;
        END;
     END WHILE;
     EXECUTE IMMEDIATE qry;
  END;
  
  CALL TEST();
  </code></pre>
  
  <p>I'd join the 'i' variable to create multiple alias for all cross tables.</p>