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 tryin
Don't use the alias (P) in your WHERE clause directly.
P
WHERE
You can either use the same REPLACE logic again in the WHERE clause:
REPLACE
SELECT Replace(Postcode, ' ', '') AS P FROM Contacts WHERE Replace(Postcode, ' ', '') LIKE 'NW101%'
Or use an aliased sub query as described in Nick's answers.