Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all records that contain a number

Tags:

sql

sql-server

It is possible to write a query get all that record from a table where a certain field contains a numeric value?

something like "select street from tbladdress where street like '%0%' or street like '%1%' ect ect"

only then with one function?

like image 327
Ivo Avatar asked Nov 29 '22 06:11

Ivo


2 Answers

Yes, but it will be inefficient, and probably slow, with a wildcard on the leading edge of the pattern

LIKE '%[0-9]%'
like image 31
martin clayton Avatar answered Dec 10 '22 03:12

martin clayton


Try this

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
like image 165
priyanka.sarkar Avatar answered Dec 10 '22 04:12

priyanka.sarkar