Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

string function to seperate full name

Posted on 2007-03-30
2
Medium Priority
?
296 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 375 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

609 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