In SQL i'm trying to return the first set of numerical values after a specific word. I only want the numbers from the string after the specific word. eg: ' hello : '
for example:
hello : 123 should return 123
hello : x123 should return 123
hello : 123 456 should return 123
cake : 10 should not return anything
So far I've worked out i need to do something like -
Declare @sInitialString varchar(max)
@sInitialString = " hello hello : 123 456"
--FIND ' hello : ' within @sInitialString
-- possibly save this a new substring or string?
-- find the first numerical value after this has been found
Seems simple but from previous posts it seems more complex.
I've managed to get all numerical values to return
DECLARE @sInitialString VARCHAR(MAX)
SET @sInitialString = (SELECT UPPER(' hello hello : 123 '))
select substring(@sInitialString,patindex('%[0-9]%',@sInitialString),100)
I just seem to be missing something either in my approach or the solution. Has anyone managed to achieve this?