开发者

Extracting nth word onwards

开发者 https://www.devze.com 2023-01-08 16:15 出处:网络
how do i extract words from the nth word onwards in sql server? eg. Description| This is a nice dress |

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

eg.

| Description |

| This is a nice dress |

extracting the 4t开发者_JAVA百科h word onwards, would output 'nice dress'


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消