Is it possible to write a WHERE condition in MS SQL Server that will grab rows that:
- begin with a specified letter
- then have a decimal
- then anything else
I basically have a table that contains postcodes and I want all postcodes that belong to Birmingham – B followed by a number. Some postcodes are in there that start B and then another letter which do not belong to Birmingham, so I can’t simply useLIKE 'B%'.
Thanks!
Use LIKE ‘B[0-9]%’. The “[0-9]” indicates any character in the range ‘0’-‘9’.
Also bear in mind that (a) someone will have typed in an “O” instead of a “0” in some cases, and that there may be some international postcodes that also start with B and a number, so if you’ve got a reliable country field, you should check that, too 🙂 Yes, I work with postcodes a lot 🙂