SELECT with a Replace()

前端 未结 8 1011
执念已碎
执念已碎 2021-01-31 09:03

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

8条回答
  •  隐瞒了意图╮
    2021-01-31 09:17

    Don't use the alias (P) in your WHERE clause directly.

    You can either use the same REPLACE logic again in the WHERE clause:

    SELECT Replace(Postcode, ' ', '') AS P
    FROM Contacts
    WHERE Replace(Postcode, ' ', '') LIKE 'NW101%'
    

    Or use an aliased sub query as described in Nick's answers.

提交回复
热议问题