Function to select data between two characters

Posted on 2013-09-13
Medium Priority
Last Modified: 2013-09-14

I have lines in my database like the below-

Call assigned to the ABCD-NL/SALES/OFFICE01/ group by DSTN (switched in group context)

Call assigned to the ABCD-NL/ADMINISTRATION/OFFICE01/ group by DSTN (switched in group context)

I want to be able to select fields in between the first two slashes -


Can you help me?
Question by:dan_stan
LVL 61

Accepted Solution

Kevin Cross earned 2000 total points
ID: 39491151
Is the 'ABCD-NL/' pre-fix always the same? It will simplify your logic if it is.

I think you can use LOCATE() or other MySQL string functions to work this out.
REFMAN: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate

If the first part is always the same, you can locate the second '/' index. Using this number, you can use the LEFT or SUBSTRING/MID function to pull out the string you want.

Author Comment

ID: 39492360
,updatetxt as department From updatedb

This did the trick, not the prettiest, but it works!


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

607 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