title: How to store the output of a query in a variable in HIVE
body: <p>I want to store current_day - 1 in a variable in <code>Hive</code>. I know there are already previous threads on this topic but the solutions provided there first recommends defining the variable outside hive in a shell environment and then using that variable inside Hive.</p>
  
  <p><a href="https://stackoverflow.com/questions/42887401/storing-result-of-query-in-hive-variable">Storing result of query in hive variable</a></p>
  
  <p>I first got the current_Date - 1 using</p>
  
  <pre><code> select date_sub(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'),1);
  </code></pre>
  
  <p>Then i tried two approaches:</p>
  
  <pre><code>1. set date1 = ( select date_sub(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'),1);
  
  and 
  
  2. set hivevar:date1 = ( select date_sub(FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd'),1);
  </code></pre>
  
  <p>Both the approaches are throwing an error:</p>
  
  <pre><code>"ParseException line 1:82 cannot recognize input near 'select' 'date_sub' '(' in expression specification"
  </code></pre>
  
  <p>When I printed (1) in place of yesterday's date the select query is saved in the variable. The (2) approach throws "{hivevar:dt_chk} is undefined
  ".</p>
  
  <p>I am new to Hive, would appreciate any help. Thanks.</p>