Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trimming Char field

Status
Not open for further replies.

andreis

Programmer
Apr 19, 2001
169
0
0
US
Hi:

I have a field with FirstName, MiddleName, and LastName entered one after another, divided by a space. How can I trim the column so that only LastName would remain?

Thanks.

Andrei
 
LEFT ( PATINDEX ( '% %', column )
 
As long your column has at least 2 fields with a space between this should work:

SELECT REVERSE(SUBSTRING(REVERSE(column_name),1,PATINDEX ('% %',(REVERSE(column_name)))-1)) from tablename

Rick.
 
"I've done this before. It may be functions by the name of "rtrim" and "ltrim" that handle this. I will keep an eye out for an answer for you - and you should search for these functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top