Solved

string function to seperate full name

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

816 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

11 Experts available now in Live!

Get 1:1 Help Now