12

我有一个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 开头?

4

5 回答 5

21
SELECT CASE WHEN ISNUMERIC(SUBSTRING(LTRIM(Description), 1, 1)) = 1 
         THEN 'yes' 
         ELSE 'no' 
       END AS StartsWithNumber
FROM Questions 
于 2012-04-20T09:54:36.797 回答
10
SELECT * FROM Questions WHERE Description LIKE '[0-9]%'
于 2017-05-24T19:24:26.507 回答
1

您可以使用以下查询。首先从左侧删除多余的空间并获得第一个左侧字符。如果不是数字,则此查询返回 0,否则返回 1。

Select ISNUMERIC(Left(Ltrim('1 This is Subheading'),1)) As Number
于 2012-04-20T10:52:59.057 回答
0
select true where cast(substring('1 This is Subheading', 1, 1) as int) between 0 AND 9
于 2012-04-20T09:54:27.840 回答
-1

select * from TABLE_NAME where (YourColName like '0%' or YourColName like '1%' or YourColName like '2%' or YourColName like '3%' or YourColName like '4%' or YourColName like '5%' or YourColName like '6%' 或 YourColName like '7%' 或 YourColName like '8%' 或 YourColName like '9%')

于 2019-06-28T05:37:17.710 回答