首页 > 解决方案 > SQL Server - 在值序列后抓取部分字符串

问题描述

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

Notes
------
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\lang1033\fs20 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

标签: sqlsql-server

解决方案


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

如果我们得到一个0ie 我们无法找到字符串,我们会将其清空。

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

推荐阅读