Reputation: 11916
I have a table Questions
with a column Description
. Its column values are like this:
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
How can I determine, for each row, if its column value starts with a number 0-9?
Upvotes: 17
Views: 42399
Reputation: 19
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%' or
YourColName like '7%' or
YourColName like '8%' or
YourColName like '9%')
Upvotes: -1
Reputation: 713
You can use the following query. Which first remove extra space form the left side and get first left character. This query return 0 if it is not numeric other wise it return 1.
Select ISNUMERIC(Left(Ltrim('1 This is Subheading'),1)) As Number
Upvotes: 1
Reputation: 460158
SELECT CASE WHEN ISNUMERIC(SUBSTRING(LTRIM(Description), 1, 1)) = 1
THEN 'yes'
ELSE 'no'
END AS StartsWithNumber
FROM Questions
Upvotes: 23
Reputation: 204766
select true where cast(substring('1 This is Subheading', 1, 1) as int) between 0 AND 9
Upvotes: 0