You need to pull out 20 words to announce the news. How to solve this in MsSql?
2 answers
if I understand your question correctly, then use substring and charindex / patindex.
- There is a field fulltext, which stores all the news. From it you need to pull out 10 words for the announcement ... - vinnie
- Can you show with an example? Che, I do not catch up - vinnie
Hey. If you need exactly 20 words. That will have to invest 19 times the search space.
Example for three spaces: text = "aba aba abba baaa ....."
Solution: Charindex ('', text, Charindex ('', text, Charindex ('', text)))
Next: cut from the beginning of the line to the space
Solution: Substring (text, 1, Charindex ('', text, Charindex ('', text, Charindex ('', text))))
But I would recommend using a different approach for the announcement. According to the average number of letters in the word 7.2 for the Russian language. 20 space will be 20 * (7.2 + 1) we get = 164 characters. Solution: Substring (text, 1, Charindex ('', text, 164))
All this, provided that there are more than 20 spaces.