title: How to store the result of a select query into a variable(IBM DB2)?
body: <p>I am trying to save the result of a query into a variable. I am using IBM DB2, but I can only store the result if I am declaring the variable inside a procedure.</p>
  
  <p>My code is:</p>
  
  <p><code>DECLARE @myvar INTEGER;
  SET @myvar = (SELECT MAX(ID) FROM S0SCSQMS.S0SRPTCNAME);</code></p>
  
  <p>and I receive the following errors:
  For the first line:"SQL0104N  An unexpected token "INTEGER" was found following "DECLARE @myvar ".  Expected tokens may include:  "END-OF-STATEMENT".  LINE NUMBER=1.  SQLSTATE=42601"</p>
  
  <p>The error code does not tell me much. I looked for it on the IBM documentation.</p>
  
  <p>Looking forward for an answer.</p>
  
  <p>Thank you.</p>