Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Substring Extraction

Posted on 2013-12-04
4
Medium Priority
?
589 Views
Last Modified: 2013-12-04
I need to use SQL to extract first name and last name from a table that stores name as follows:

last_name, first_name mi

ex: 'Doe, Jane L'
      'Smith Jr., Frank C'
      'Brown M.D., Lawrence'

Thanks!
0
Comment
Question by:PattiN
[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
4 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39696397
select last_name&', '&first_name&' '&mi from table

Open in new window

If that doesn't work, replace all of the & with || - I can't remember which is the correct syntax in Sybase.
0
 

Author Comment

by:PattiN
ID: 39696445
I wasn't clear, sorry.  I mean that I need to extract first name as one field and last name as another field from a column in a table that stores the whole name as 'last name, first name mi'.  So, in my example above, I need the following results:

from:  'Doe, Jane L'
         'Smith Jr., Frank C'
         'Brown M.D., Lawrence'

I need two columns in my SQL result set:
First Name             Last Name
Jane                         Doe
Frank                       Smith Jr.
Lawrence                Brown M.D.
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 1500 total points
ID: 39696807
So what you basically want to do is take out the string, spit it by ',' to separate last name from first/middle and then split first/middle by a space to separate them.

I'm not familiar with how Sybase works with SQL, but this article on splitting strings should contain something that will work for you
http://www.sqlperformance.com/2012/07/t-sql-queries/split-strings

Look especially at the one called "Jeff Moden's splitter." I think that will work for you.

Note that all the comments and discussion on performance won't really apply to you since your strings are relatively short (nowhere near 8000 characters).
0
 

Author Closing Comment

by:PattiN
ID: 39696825
That's great, thank you!
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

719 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