Solved

string function to seperate full name

Posted on 2007-03-30
2
253 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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.

911 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

19 Experts available now in Live!

Get 1:1 Help Now