title: conditional select between multiple fields
body: <p>I have a table with a certain flag called FL_virtual, if this flag equals 1 i need to get my stock in a special way using a function</p>
  
  <p>now i want to make a select statement with it but depending on this flag i need to adjust my select to use a certain function instead of a subquery</p>
  
  <p>so presume i start with this select statement</p>
  
  <p><code>select product_name,..(other options from the product table), 
  (select sum(qy_stock) from STOCK where warehouse_id = 1) as 'qy_stock_internal',
  (select sum(qy_stock) from STOCK where warehouse_id = 2) as qy_stock_external 
  From product</code></p>
  
  <p>now i need to change the subquery (qy_stock) with a call to a function when the fl_virtual flag is 1</p>
  
  <p>so that it becomes like this</p>
  
  <p><code>select product_name,..(other options from the product table),
   FN_GET_stock_PRODUCT(1) as qy_stock_internal,
   FN_GET_stock_PRODUCT(2) as qy_stock_external
  from product</code></p>
  
  <p>so i thought a simple if then else structure will do but for some reason i can't get it to work
  this is how i thought it would look</p>
  
  <pre><code>select product_name,..(other options from the product table),
   IF fl_virtual &gt; 0 THEN 
  (select sum(qy_stock) from STOCK where warehouse_id = 1) as 'qy_stock_internal',
  (select sum(qy_stock) from STOCK where warehouse_id = 2) as qy_stock_external
  
  ELSE  
  
  FN_GET_stock_PRODUCT(1) as qy_stock_internal,
  FN_GET_stock_PRODUCT(2) as qy_stock_external
  END IF
  </code></pre>
  
  <p>but it doesn't work , anyone got an idea?</p>