title: Changing T-SQL variable in union statement
body: <p>I want to change a variable value from one part of a union statement to another:</p>
  
  <p>e.g.</p>
  
  <pre><code>USE db1
  DECLARE @x int;
  set @x = 5;
  SELECT * FROM  [db1].[Schema1].[table1]
  where intCol1 &lt;= @x
  UNION
  --set @x = 10;  -- doesn't allow me to change variable here
  SELECT * FROM  [db1].[Schema1].[table1]
  where intCol1 &lt;= @x
  
  -- in this case a work-around would be to use where intCol1 &lt;= (2 * @x) in the last line.
  </code></pre>
  
  <p>But what is the point of variables if you cannot change them?</p>
  
  <p>Is there a away to change the variable to have different values in different parts of the select statement, or is that intrinsically impossible?</p>
  
  <p>Since all numbers &lt; 5 are also &lt; 10, I realize the answer is the same if you just do a single SELECT with where intCol1 &lt;= ( 2* @x)
  however, this is a simplified version of a much bigger query scheme ...</p>
  
  <p>Thanks in advance for your attention</p>