title: SELECT with a Replace()
body: <p>I have a table of names and addresses, which includes a postcode column. I want to strip the spaces from the postcodes and select any that match a particular pattern. I'm trying this (simplified a bit) in T-SQL on SQL Server 2005:</p>
  
  <pre><code>SELECT Replace(Postcode, ' ', '') AS P
  FROM Contacts
  WHERE P LIKE 'NW101%'
  </code></pre>
  
  <p>But I get the following error;</p>
  
  <pre><code>Msg 207, Level 16, State 1, Line 3
  Invalid column name 'P'.
  </code></pre>
  
  <p>If I remove the WHERE clause I get a list of postcodes without spaces, which is what I want to search. How should I approach this? What am I doing wrong?</p>