sql - 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
解决方案
我们用于PATINDEX
查找第一次出现的fs
后跟两位数字。
如果我们得到一个0
ie 我们无法找到字符串,我们会将其清空。
SUBSTRING(Note, NULLIF(PATINDEX('%fs[0-9][0-9]%', Note), 0) + 4, LEN(Note))
推荐阅读
- json - 使用 jq 的 Ansible 输出提取包版本
- ruby - 可以以位置和关键字方式提供的参数?
- javascript - 转换 Node 项目中两个 SQL DB 之间传递的值
- css - 在 Angular 中悬停时旋转 FontAwesome 图标
- html - 从 HTML 转换为字符串 XQuery
- javascript - 为侧边菜单创建外部文件
- azure - 带有 SAS 令牌的 Azure Blob 存储
- python - Request.POST.get 在 django 中对我不起作用,返回默认值
- reactjs - React 中的 Openlayers 弹出窗口不遵循地图缩放
- javascript - 数据属性无法从 foreach 中获取动态 ID