martin.griffiths (2/27/2008)
I'm currently trying to write a query that will extract the first two words from a string. I'm using charindex and substrings and it's getting quite messy! Has anyone ever written a function may be to extract a specific number of words i.e. text around spaces please? It would need to be able to cope with data where there are different lengths and number of words such as:This is the first line
Second line
Word
This is the fourth line
and if I was asking it to return a string containing the first two words the results would be:
This is
Second line
Word
This is
Thanks.
Just curious... what will this be used for? In other words, why do you need to do this?
--Jeff Moden
Change is inevitable... Change for the better is not.