SELECT with a Replace()

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

    You can reference is that way if you wrap the query, like this:

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

    Be sure to give the wrapped select an alias, even unused (SQL Server doesn't allow it without one IIRC)

提交回复
热议问题