title: Can I call a stored procedure in a cfloop and output dynamic out-parameters in Coldfusion?
body: <p>Last question for tonight, still using Coldfusion8 and MySQL.</p>
  
  <p>I have a table with products, each with Price A, B and C. I need to retrieve the min and max values for A,B,C across all prices (A_min, A_max, B_min, B_max, C_min, C_max)</p>
  
  <p>I thought I would create a stored procedure and loop through A,B,C like so:</p>
  
  <pre><code>  &lt;cfloop list="A,B,C" index="what" delimiters=","&gt;
      &lt;cfstoredproc procedure="proc_search_select_minmax" datasource="dtb"&gt;
          &lt;cfprocparam type="in" value="#what#" cfsqltype="cf_sql_varchar" maxlength="15"&gt;
          &lt;cfprocparam type="in" value="#variables.xxx#" cfsqltype="cf_sql_varchar" maxlength="13"&gt;
          &lt;cfprocparam type="in" value="#variables.yyy#" cfsqltype="cf_sql_varchar" maxlength="13"&gt;
          &lt;cfprocparam type="in" value="#variables.zzz#" cfsqltype="cf_sql_text" maxlength="4"&gt;
          &lt;cfprocparam type="out" cfsqltype="cf_sql_decimal" variable="#what#_min"&gt;
          &lt;cfprocparam type="out" cfsqltype="cf_sql_decimal" variable="#what#_max"&gt;   
       &lt;/cfstoredproc&gt;
    &lt;/cfloop&gt;
  </code></pre>
  
  <p>So the idea was to run this three times for A,B and C and get variables A_min, A_max, B_min... out of the loop. </p>
  
  <p>But I'm having trouble with my out-parameters, which inside MySQL, I'm declaring like:</p>
  
  <pre><code> CREATE ... PROCEDURE `proc_search_select_minmax`(..., OUT `outputMin` DECIMAL(12,2), OUT `outputMax` DECIMAL(12,2))
  
   .... 
   SET outputMin = min(what);
   SET outputMax = max(what);
  </code></pre>
  
  <p>Coldfusion error says: </p>
  
  <pre><code>Error Executing Database Query
  @
  &lt;cfprocparam type="out" cfsqltype="cf_sql_decimal" variable="#what#_min"&gt;
  &lt;cfprocparam type="out" cfsqltype="cf_sql_decimal" variable="#what#_max"&gt;
  </code></pre>
  
  <p><strong>Questions:</strong><br>
  Do I have to give my out parameters the same name as inside MySQL or is the correct order enough?<br>
  More importantly, can I set output variables dynamically like this? If not, are there any other ways except calling the stored procedure three separate times?</p>