Solved

string function to seperate full name

Posted on 2007-03-30
2
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

749 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