hi, 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'
hi, 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'
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.
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