title: DB2 insert row if not exist with value from parameter
body: <p>I want to insert a row into a table if it doesn't exists yet. I have following code that executes directly:</p>
  
  <pre><code>insert into MyTable (Column1, Column2, Year, Code, Id, UPDATE_IDENT)
  select 'Default', 'Default', 2014, '', 0, 0
  from sysibm.sysdummy1
  WHERE NOT EXISTS (SELECT * FROM MyTable 
  WHERE Column1 = 'c1'
  AND Column2 = 'c2'
  AND Year = 2014)
  </code></pre>
  
  <p>However when i change this to a paramtered method by year:</p>
  
  <pre><code>insert into MyTable (Column1, Column2, Year, Code, Id, UPDATE_IDENT)
  select 'Default', 'Default', @year, '', 0, 0
  from sysibm.sysdummy1
  WHERE NOT EXISTS (SELECT * FROM MyTable 
  WHERE Column1 = 'c1'
  AND Column2 = 'c2'
  AND Year = @year)
  </code></pre>
  
  <p>Also tried with a declared variable in an atomic part with no success:</p>
  
  <pre><code>BEGIN ATOMIC
  DECLARE varJaar INTEGER;
  SET varYear = @year;
  insert into MyTable (Column1, Column2, Year, Code, Id, UPDATE_IDENT)
  select 'Default', 'Default', varYear , '', 0, 0
  from sysibm.sysdummy1
  WHERE NOT EXISTS (SELECT * FROM MyTable 
  WHERE Column1 = 'c1'
  AND Column2 = 'c2'
  AND Year = varYear )
  END;
  </code></pre>
  
  <p>I cannot execute this because i cannot use a parameter in my select part.  Tried to modify @year to @year as Year, but still no success.</p>
  
  <p>Is there a way i can declare a temp variable or something to use this parameter in my select part?</p>