简体   繁体   English

用数字选择所有字符串

[英]SELECT all strings with numbers

I have a long list in a varchar column (SQL Server) with data like: 我在varchar列(SQL Server)中有一个长列表,其中包含以下数据:

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? 如何使用SELECT SQL执行此操作?

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

You can Use Regular Expression [0-9] which will select all rows with numbers between 0 and 9 您可以使用正则表达式[0-9] ,它将选择数字介于0和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 OUTPUT

Hello World 3 你好世界3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM