title: getting invalid column error in SQL Server
body: <p>I have the following query:</p>
  
  <p>The value in the TimeStamp columns is <code>201403240004</code> so the following function converts it in the format: <code>2014-03-24 00:04:00.000</code></p>
  
  <pre><code>SELECT CONVERT(DATETIME,
     SUBSTRING([TimeStamp],1,4)+'-'+SUBSTRING([TimeStamp],5,2)+'-'
    +SUBSTRING([TimeStamp],7,2)+' '+SUBSTRING([TimeStamp],9,2)+':'
    +SUBSTRING([TimeStamp],11,2)+':00.000') AS MessageDate
  FROM Table
     WHERE MessageDate = '2014-03-24 00:04:00.000'
  </code></pre>
  
  <p>When I am trying to use <code>MessageDate</code> in WHERE clause, why do I get invalid column name error in sqlserver? How can I use the converted <code>MessageDate</code> in my WHERE clause?</p>