Extracting nth word onwards
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.
精彩评论