Solved

string function to seperate full name

Posted on 2007-03-30
2
241 Views
Last Modified: 2012-05-05
Hello all,
    I am looking for a string function to seperate my lastname, firstname and middlename and put into three seperate columns. so here is my table

Table1:
FullName
Lym, Sherry Anne

like in the above example. i have a table in which there is a fullname column. the format of this colum is LastName, FirstName MiddleName. now i want to last name, firstname and middlename first initial, in three seperate columns. that would be something like this

ResultTable:
LastName      FirstName   MiddleInitial
Lym                 Sherry         A

please provide me a sql query...thanks
0
Comment
Question by:k_rasuri
2 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 18824675
Select Left(FullName,CHARINDEX(',',FullName,1)-1),
       SUBSTRING(FullName,CHARINDEX(',',FullName,1)+2,CHARINDEX(' ',FullName,CHARINDEX(' ',FullName,1)+1)-CHARINDEX(',',FullName,1)-2),
       SUBSTRING(FullName,CHARINDEX(' ',FullName,CHARINDEX(' ',FullName,1)+1)+1,1) from Table1
0
 
LVL 5

Expert Comment

by:nakul_vachhrajani
ID: 18848384
As a general rule for such tasks:
1. Determine what your delimiters are
2. Search for the same in your source column name; thus dividing the script into parts
3. Save the parts into various columns.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now