SELECT with a Replace()

前端 未结 8 1018
执念已碎
执念已碎 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:30

    You have to repeat your expression everywhere you want to use it:

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

    or you can make it a subquery

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

提交回复
热议问题