title: Fire multiple select from one table and insert the result into Target table using node-red dashdb-in and dashdb-out modules
body: <p>I am trying to achieve to read from a DB2 table and insert to a different DB2 table using node-red.  For this i am using dashdb modules(<a href="https://flows.nodered.org/node/node-red-nodes-cf-sqldb-dashdb" rel="nofollow noreferrer">https://flows.nodered.org/node/node-red-nodes-cf-sqldb-dashdb</a>). I have made sure that columns are matching in both source and target and tested to insert multiple records in target table using  select query as select * from source_table and then insert query for the insert table.
  Now i have another thing in which i need to fire multiple select queries on source table and insert the result records in target table asynchronously.
  All the multiple select queries would be identical except where id = ? . So i tried to put the query in msg.payload inside a for loop like this</p>
  <pre><code>var queryID = 2; // max number of id to be querying against
              for (i=1; i&lt;=queryID; i++) { 
                  console.log(&quot;COUNT&quot;, i)
                  msg.payload = `select * from source_table where id= ${i}` // only i changes
                  node.send(msg); // i pass it to next node which is dashBD out node responsible for selecting record from source table
              } 
  </code></pre>
  <p>But doing this only executes the last  loop value which is 2 and do not node.send the value where i = 1 to the next node.</p>
  <p>Can anyone shed some light here: It inserts the result with id=2 two times in the target table. Instead i want to execute insert according to the for loop i variable. This is the second node module function in the graph</p>
  <pre><code>module.exports = function(RED) {
  function fireMultipleQuery(nodeConfig) {
      RED.nodes.createNode(this,nodeConfig);
      var node = this;
      node.on('input', function(msg) {
          var queryID = 2; // max number of id to be querying against
          for (i=1; i&lt;=queryID; i++) { 
              console.log(&quot;COUNT&quot;, i)
              msg.payload = `select * from source_table where id= ${i}` // only i changes
              node.send(msg); // i pass it to next node which is dashBD out node responsible for selecting record from source table
          });
  
       }
      RED.nodes.registerType(&quot;fire-query-node&quot;, fireMultipleQuery);
  }
  </code></pre>
  <p>This is my flow
  <a href="https://i.stack.imgur.com/x5n5a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x5n5a.png" alt="enter image description here" /></a></p>