11

I need to select just the rows within a sql table which contain no numerical values whatsoever, here's an example table:

AddressLine1
-------------
59 Prospect Road
Rose House
24 St. Pauls Place
1 Oxford Avenue
9 Stonecross Road
65 Wood Common
19 Falcon Close
Thorn House
16 Poplars Close
52 Coombes Road
12 Brinsmead
14 Meadow Close
15 Rowlatt Drive

In this example I would just be looking for "Rose House" and "Thorn House" rows to be returned.

Any suggestion on the code I should be using would be gratefully received.

3
  • You can consider using regular expressions, some examples you will find here on StackOverflow
    – TT.
    Jan 7, 2016 at 10:33
  • Hi @adam-haycok , ah ... better formatting ... ah ... 2 thumbs up | pat in the back | high 5
    – Andy K
    Jan 7, 2016 at 10:38
  • Some answers were given but the better option would be to split it up in two columns: AddressNumber and AddressName.
    – Carra
    Jan 7, 2016 at 10:39

3 Answers 3

23
select * from tab
where AddressLine1 not like '%[0-9]%'

try this

2
  • You are Welcome @Adam Feb 23, 2016 at 16:10
  • Using this query I am not able to get non numeric values that have an alpha character in the middle of the value
    – Sandhya
    Jul 23, 2020 at 18:34
10

I think the actual answer should be:

select * from tab where AddressLine1 like '%[^0-9]%'

According to: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-ver15

0

This is the way:

SELECT * FROM TABLE_NAME WHERE NOT REGEXP_LIKE(COLUMN_NAME, '^-?[0-9.]+$');

This also excludes values which contain decimals.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.