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.

Adam Haycock
  • 167
  • 1
  • 1
  • 7
  • You can consider using regular expressions, some examples you will find [here](https://stackoverflow.com/questions/8928378/using-regex-in-sql-server) on StackOverflow – TT. Jan 07 '16 at 10:33
  • Hi @adam-haycok , ah ... better formatting ... ah ... 2 thumbs up | pat in the back | high 5 – Andy K Jan 07 '16 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 07 '16 at 10:39

3 Answers3

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

try this

Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43
Akshey Bhat
  • 8,227
  • 1
  • 20
  • 20
9

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

INS
  • 10,594
  • 7
  • 58
  • 89
0

This is the way:

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

This also excludes values which contain decimals.

Indru
  • 3
  • 1