提取第 n 个单词以后

发布于 2024-09-11 13:28:59 字数 113 浏览 0 评论 0原文

如何在 sql server 中提取从第 n 个单词开始的单词?

例如。

|描述 |
|这件衣服真好看|

从第四个单词开始,将输出“nice dress”

how do i extract words from the nth word onwards in sql server?

eg.

| Description |
| This is a nice dress |

extracting the 4th word onwards, would output 'nice dress'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮烟 2024-09-18 13:28:59
with sentences as
(
select 'short sentence' as sentence UNION ALL
select 'This is a nice dress' as sentence UNION ALL
select 'The quick brown fox jumped over the lazy dog' as sentence 
)

SELECT 
SUBSTRING(sentence,
CHARINDEX(' ', sentence,CHARINDEX(' ', sentence, CHARINDEX(' ', sentence)+1)+1),
LEN(sentence)) AS WordFourOnwards
FROM sentences
WHERE patindex('[^ ]% [^ ]% [^ ]% [^ ]%',sentence) > 0
with sentences as
(
select 'short sentence' as sentence UNION ALL
select 'This is a nice dress' as sentence UNION ALL
select 'The quick brown fox jumped over the lazy dog' as sentence 
)

SELECT 
SUBSTRING(sentence,
CHARINDEX(' ', sentence,CHARINDEX(' ', sentence, CHARINDEX(' ', sentence)+1)+1),
LEN(sentence)) AS WordFourOnwards
FROM sentences
WHERE patindex('[^ ]% [^ ]% [^ ]% [^ ]%',sentence) > 0
毁虫ゝ 2024-09-18 13:28:59

如果您自己构建该方法,您可以找到第三个空格的字符串位置,然后从该位置获取正确的字符串。

编辑:charindex() 和 substring() 的组合等。

If you build the method yourself, you could find the string position for the third space, and then take the right string from that position.

Edit: combination of charindex() and substring(), etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文