I am using Sql Serevr 2008
How can I count the number of digits in a database field , something along these lines:
select headline,
REGEXP_count(name,'\d') as num_count
from accountTbl
where num_count > 3;
I am trying to detect if somebody has written more then 3 numeric digits in their headline text.
For example I want to catch:
'hello call me on 3 4 5 6 7 8' - match
'this is my number 234875' - match
'4 hello 4 and 66' - match
'leaving on the 24th going to be there at 6:30' - match
SQL Server 2008 does not support regular expressions; only patterns are supported. You can use a query like this to find matches of three digits or more:
You wouldn’t get the count, but you would be able to filter. The downside to this solution is that in order to search for, say, five digits you would need to change the pattern itself.
Here is a quick demo on sqlfiddle.