Get all records containing a number

Can I write a query to get this whole record from a table, where does a specific field contain a numerical value?

something like "select a street from tbladdress where a street is like"% 0% "or a street like"% 1% "etc."

only then with one function?

+3
source share
5 answers

try it

declare @t table(street varchar(50))
insert into @t 
    select 'this address is 45/5, Some Road' union all
    select 'this address is only text'

select street from @t
where street like '%[0-9]%'

Street

this address is 45/5, Some Road
+13
source

Yes, but it will be inefficient and probably slow, with a wildcard at the front edge of the template

LIKE '%[0-9]%'
+6
source

( , , ).

, , - ( ) ( ), , hasNumerics , , insert/update , .

, , , , . , , select.

, , :

select * from mytable where hasNumerics = 1; -- or true or ...

, like '%...%' .

+1
source

I found this solution "select a street from tbladresse with (nolock), where patindex ('% [0-9]%', street) = 1"

it took me 2 minutes to find 3 million on an unindexed field

0
source

To get strings containing only numbers, use this query

select street 
from tbladdress 
where upper(street) = lower(street)

Works in oracle.

0
source

Source: https://habr.com/ru/post/1724082/


All Articles