title: Change date on query based on result of a colomn from another table
body: <p>I have an sql query like this:</p>
  
  <pre><code>WITH CUR_DATE AS(
   SELECT to_date(cur_value, 'DD/MM/YYYY') AS cur_value
   FROM PARAMS
   WHERE id = 'CURRENT_SERVER_DATE'
  )
  SELECT 
     cur_date.cur_value - 1 as date_cal,
     iar.allocation_date
  FROM POS
   CROSS JOIN CUR_DATE
   INNER JOIN REFERENCE
     ON RC.reference_id = REFERENCE.id
  </code></pre>
  
  <p>and I wish to modify the value of 'date_cal' upon the result of 'GENERATION_TYPE' from another query :</p>
  
  <pre><code>select distinct(GENERATION_TYPE) 
   from VVV_PICKING_HIST where CREATION_DATE =    (select MAX(CREATION_DATE)
   from VVV_PICKING_HIST
  </code></pre>
  
  <p>Means that if GENERATION_TYPE = "NO" I leave cur_date.cur_value - 1 otherwise I remove the -1 and I'll have </p>
  
  <pre><code>cur_date.cur_value as date_cal
  </code></pre>
  
  <p>I don't know how to merge the two queries and use for example</p>
  
  <pre><code>CASE WHEN GENERATION_TYPE = "NO" 
  THEN cur_date.cur_value - 1 AS DATE_CAL  ELSE cur_date.cur_value AS DATE_CAL
  </code></pre>