Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 String function - return only whole words

Author  Topic 

jackstow
Posting Yak Master

160 Posts

Posted - 2003-06-03 : 11:49:01
In a select statement for a search

cast(Posts.Body as nvarchar(30)) + '...' as Body

returns

body
----
Hello guys, is there anybody w...


What I want is:

body
----
Hello guys, is there anybody...


Anybody got a nice little bit of string manipulation code to find the last blank space and then trim so avoiding trailing letters? ;)


Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-06-03 : 12:03:55
OK

There HAS to be a better way that this :


select Substring( cast( Posts.Body as nvarchar(30)), 1, 30 - Charindex( ' ', reverse( cast( Posts.Body as nvarchar(30)) ) )) + '...' as Body






Damian
Go to Top of Page

alemos
Starting Member

16 Posts

Posted - 2007-12-19 : 08:50:24
There is another way. Read this article:
http://www.sqlteam.com/article/returning-complete-words-from-a-substring
Go to Top of Page
   

- Advertisement -