title: Running Multiple Sql Commands in a Loop
body: <p>I successfully executed the sql code below from an msql editor (phpmyadmin), testing it with one customer (where <code>Customer No</code>=1). I need to now run the sql script for all the customers. </p>
  
  <pre><code>START TRANSACTION;
  INSERT INTO `addresses` (`AddressLine1`,`CityID`,`ProvStateCode`,`AddressPostCode`,`CountryIso`) SELECT `Bill To Address`,`Bill To City`,`Bill To Province`,`Bill Code`,`Country` FROM `pdx_customers` where `Customer No`=1;
  SELECT @last_id := LAST_INSERT_ID();
  SELECT `Customer No` FROM `pdx_customers` 
  INSERT INTO `customer_addresses` (`CustID`,`AddressID`,`AddressTypeID`) Values(1,@last_id,1);
  COMMIT;
  </code></pre>
  
  <p>It seems I would need to create a stored procedure ? In a loop, I need to get the <code>Customer No</code> dynamically for each row in the <code>pdx_customers</code> table, and enter into the Values clause in the insert command, i.e Values(@CustID,@last_id,1). Not sure how I would do this ? </p>
  
  <p>Any help would be appreciated. 
  Thanks </p>