Solved

SQL Substring Extraction

Posted on 2013-12-04
4
539 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

747 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

9 Experts available now in Live!

Get 1:1 Help Now