Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

determine if column value string starts with a number

Tags:

sql-server

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?

like image 953
Hari Gillala Avatar asked Apr 20 '12 09:04

Hari Gillala


Video Answer


2 Answers

SELECT CASE WHEN ISNUMERIC(SUBSTRING(LTRIM(Description), 1, 1)) = 1 
         THEN 'yes' 
         ELSE 'no' 
       END AS StartsWithNumber
FROM Questions 
  • ISNUMERIC
  • SUBSTRING
like image 157
Tim Schmelter Avatar answered Oct 10 '22 20:10

Tim Schmelter


SELECT * FROM Questions WHERE Description LIKE '[0-9]%'
like image 42
Ben Curthoys Avatar answered Oct 10 '22 22:10

Ben Curthoys