title: SQL Server : executing query conditionally
body: <p>I have <code>Employees</code> tables in the database with a column <code>EmpID</code> which was changed to <code>ID</code>. I want to use the same query in both the old and new table and get the same result depending on the condition. </p>
  
  <p>I have tried the following:</p>
  
  <pre><code>IF (COL_LENGTH('Employees', 'EmpID') IS NOT NULL)
      SELECT EmpID, NAME, SEX, SALARY
      FROM Employees
      WHERE EmpID IS NOT NULL
  ELSE
      SELECT ID, NAME, SEX, SALARY
      FROM Employees
      WHERE ID IS NOT NULL
  </code></pre>
  
  <p>But when I run the query in the new table, I get column name <code>EmpID</code> doesn't exist error. Any help is appreciated!</p>