Solved

SQL Substring Extraction

Posted on 2013-12-04
4
551 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
  • 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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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