title: DB2 dynamic table name
body: <p>I want to count the rows of a number of tables. But the table name should be used dynamically. I want to do that within one SQL statement.</p>
  
  <p>I tried it with</p>
  
  <pre><code>BEGIN ATOMIC 
    FOR tmp AS (
      SELECT tabschema || '.' || tabname tbl 
      FROM syscat.tables WHERE tabname LIKE '%CD') DO 
         (SELECT COUNT(*) FROM tmp.tbl); 
    END FOR; 
  END
  </code></pre>
  
  <p>but I receive the error</p>
  
  <pre><code>DB21034E  The command was processed as an SQL statement because it was not a 
  valid Command Line Processor command.  During SQL processing it returned:
  SQL0204N  "TMP.TBL" is an undefined name.  LINE NUMBER=1.  SQLSTATE=42704
  </code></pre>
  
  <p>and found no other working solution...</p>
  
  <p>Is there a solution for that?
  Thanks in advance.</p>