SQL Server语言 - 在一个值序列之后抓取字符串的一部分



我有一个名为Note的表,其中有一个名为Notes的列。

Notes
------
{rtf1ansideff0{fonttbl{f0fnilfcharset0 Arial;}}
viewkind4uc1pardlang1033fs20 called insurance company they are waiting to hear from the claimant's attorney

开头有我不需要的字体信息。我已经创建了一个新的列名final_notes,并希望抓取"fs"之后的一切加上两个字符。最后的结果是

final_notes
-----------
called insurance company they are waiting to hear from the claimant's attorney

我们使用PATINDEX来查找fs后跟两位数字的第一次出现

如果我们得到一个0,我们将其空,即我们找不到字符串。

SUBSTRING(Note, NULLIF(PATINDEX('%fs[0-9][0-9]%', Note), 0) + 4, LEN(Note))

最新更新