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.
| 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 BOBBIBILLY BOB JIM would become BILLYSAMUEL JOHN SMAPDY WHIZZLESNOT would be SAMUELDoes 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 belowSELECT LEFT(field,CASE WHEN CHARINDEX(' ',field) > 0 THEN CHARINDEX(' ',field)-1 ELSE LEN(field) END) FROM table------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-09 : 11:20:33
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|