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
 General SQL Server Forums
 New to SQL Server Programming
 Is this an RTRIM task?

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-03-09 : 10:57:39
I have a column which i need to trim down to just the first set of characters before the first space in the string. Some entries have one space in the cell and other have two or three. Bottom line is in each, i need only the first group of characters to remain. For example:

BOBBI JO would become BOBBI
BILLY BOB JIM would become BILLY
SAMUEL JOHN SMAPDY WHIZZLESNOT would be SAMUEL

Does this call for a RTRIM script?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 11:00:13
nope. it should be below

SELECT LEFT(field,CASE WHEN CHARINDEX(' ',field) > 0 THEN CHARINDEX(' ',field)-1 ELSE LEN(field) END) FROM table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-03-09 : 11:19:13
Thank you. Now i suppose it's understanding why it's not an rtrim task. off to the google sage.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 11:20:33
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -