确定列值字符串是否以数字开头

时间:2012-04-20 09:48:37

标签: sql-server

我有一个表Questions,其中包含Description列。它的列值如下:

This is First Heading, 
1 This is Subheading one, 
1.2 This is subheading Question
This is Second heading
2 This is subheading Two.
2.1 This is Subheading Question1

如何为每一行确定其列值是否以数字0-9开头?

是否有任何SQL Server 2008+功能?

5 个答案:

答案 0 :(得分:18)

SELECT CASE WHEN ISNUMERIC(SUBSTRING(LTRIM(Description), 1, 1)) = 1 
         THEN 'yes' 
         ELSE 'no' 
       END AS StartsWithNumber
FROM Questions 

答案 1 :(得分:5)

SELECT * FROM Questions WHERE Description LIKE '[0-9]%'

答案 2 :(得分:1)

您可以使用以下查询。首先从左侧移除额外的空格并获得第一个左侧角色。如果此查询不是数字,则返回0,否则返回1.

Select ISNUMERIC(Left(Ltrim('1 This is Subheading'),1)) As Number

答案 3 :(得分:0)

select true where cast(substring('1 This is Subheading', 1, 1) as int) between 0 AND 9

答案 4 :(得分:0)

从TABLE_NAME中选择*,其中(YourColName如'0%'或YourColName如'1%'或YourColName如'2%'或YourColName如'3%'或YourColName如'4%'或YourColName如'4%'或YourColName如'5%'或YourColName(如“ 6%”)或YourColName(如“ 7%”)或YourColName(如“ 8%”)或YourColName(如“ 9%”))