title: Using IF or Case to determine what field to use in a WHERE statement
body: <p>I have a table with</p>
  
  <pre><code>Name   EnteredDateID  RecvdDateID
  
  A      20140901       20240901    
  B      20140901       20140901
  C      20140901       20140901
  D      20140901       20140901
  E      20140901       20110901
  F      20140901       20140901
  G      20140901       20110901
  </code></pre>
  
  <p>I need to write a query that would do the following</p>
  
  <pre><code>SELECT * FROM TABLEA WHERE
  </code></pre>
  
  <p>and this is where I'm falling over</p>
  
  <pre><code>IF RecvdDateID &gt; GETDATE() THEN USE 
  EnteredDateID &gt; 20140630 
  ELSE USE THE 
  RecvdDateID  &gt; 20140630 
  </code></pre>
  
  <p>So I would end up with</p>
  
  <pre><code>Name   EnteredDateID  RecvdDateID
  
  A      20140901       20240901    
  B      20140901       20140901
  C      20140901       20140901
  D      20140901       20140901
  F      20140901       20140901
  </code></pre>