Farhan Hafeez
Farhan Hafeez

Reputation: 644

SELECT all strings with numbers

I have a long list in a varchar column (SQL Server) with data like:

Hello World
Hello World 2
1 Hello World
Again this is Hello World
Hello 100 World
500

I want to SELECT all the strings which contain a number in it. For example, in above, I need:

Hello World 2
1 Hello World
Hello 100 World
500

How can I do it with SELECT SQL?

Upvotes: 2

Views: 134

Answers (2)

Dgan
Dgan

Reputation: 10285

You can Use Regular Expression [0-9] which will select all rows with numbers between 0 and 9

Declare @tab as table(data varchar(50))
 insert into @tab values
 ('Hello World 3'),('Hello World')
 select * from @tab where data like '%[0-9]%'

OUTPUT

Hello World 3

Upvotes: 3

Mudassir Hasan
Mudassir Hasan

Reputation: 28751

SELECT * 
FROM tableName
WHERE columnName like '%[0-9]%'

Upvotes: 5

Related Questions