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)
 Extract Last Name from Full Name

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-12 : 09:41:42
Mary writes "Is there a way to extract just the last name from a field that contains the full name? For example, my database has a field called FullName which has the customer's full name, Tom T. Jones, and I would like to extract just the last name, Jones."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 09:46:06
eg

declare @name varchar(100)
set @name='Tom T. Jones'
select substring(@name, charindex(' ',reverse(@name),1)+1,len(@name))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-12 : 10:13:31
Or

declare @name varchar(100)
set @name='Tom T. Jones'
select Right(@name, charindex(' ',@name)+1)


Srinika
Go to Top of Page
   

- Advertisement -