在 SQL 中,我试图在特定单词之后返回第一组数值。我只想要特定单词之后的字符串中的数字。例如:'你好:'
例如:
hello : 123 should return 123
hello : x123 should return 123
hello : 123 456 should return 123
cake : 10 should not return anything
到目前为止,我已经知道我需要做一些类似的事情 -
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
看起来很简单,但从以前的帖子来看,它似乎更复杂。
我设法让所有数值返回
DECLARE @sInitialString VARCHAR(MAX)
SET @sInitialString = (SELECT UPPER(' hello hello : 123 '))
select substring(@sInitialString,patindex('%[0-9]%',@sInitialString),100)
我似乎在我的方法或解决方案中遗漏了一些东西。有没有人设法做到这一点?