title: Declare a variable in DB2
body: <p>I am a total novice in DB2.  I am trying to help someone else out who is an SQL Novice.</p>
  
  <p>What I am trying to do would look like this in SQL Server:</p>
  
  <pre><code>declare @MaxValue int
  select @MaxValue = Max(ID_COLUMN) from MainTable 
  
  insert into MainTable (ID_COLUMN, OTHER_STUFF)
  select TEMP_ID + @MaxValue, MORE_OTHER_STUFF
  from   TempTable
  </code></pre>
  
  <p>How can I do this in DB2?  (Bonus points if you can tell me a way to do this so that the inserted values into ID_COLUMN just keep counting from the current max.)</p>
  
  <p>Note: I see a lot of examples saying you can declare a variable like this</p>
  
  <pre><code>DECLARE myvariable int;
  </code></pre>
  
  <p>but that is erroring out for us.  So if you use that syntax maybe you can comment on why that does not work.</p>