title: Sql Server union with If condition
body: <p>I have a query like:</p>
  
  <pre><code>DECLARE @tmpValue
  SET @tmpValue = 0 -- it will be change 
  
  SELECT * FROM Animal WHERE AniActive = 1
  UNION 
  IF @tmpValue &gt; 0 
  SELECT * FROM Animal WHERE.Active = 0
  </code></pre>
  
  <p>When I use like this it is giving error because of if condition. I have to use UNION because of our structure. </p>
  
  <p>How can I use it with if condition?</p>
  
  <p>Thanks, <br/>
  John</p>