title: how to generate and run dynamic sql in vertica
body: <p>I am planning to maintain logic for a derived field in a look up table and thinking of running dynamic  sql statements real time.</p>
  
  <p>for example , if field company_type is derived based on the following logic </p>
  
  <p><code>case when substr(company_code,1,3)='XYZ' then substr(comapny_code,4,6)
       when substr(company_code,1,3)='ABC' then substr(company_code,7,9)
       else substr(company_code,1,3) end;</code> </p>
  
  <p>to avoid code changes whenever a new case is provided by business i want to maintain the logic in a look up table like following </p>
  
  <pre><code>order          src_filed                               src_value 
  --------------------------------------------------------------
    1     substr(company_code,1,3)='XYZ'          substr(4,6)
    2     substr(company_code,1,3)='ABC'          substr(7,9)
    3                                             substr(1,3)
  </code></pre>
  
  <p>now based on the data in look up table , i want to be able to generate case statement dynamically and to be able to run the case statemnent. Note that i need to run that dynamic sql as part of another sql where i query source tables that has source fields.</p>