Solved

How do I select only the value that is between parenthesis

Posted on 2008-06-15
1
187 Views
Last Modified: 2010-03-20
The database saves to a field "logonname (Full Name)". I have a field in a select query RequestedBy and I want the results of the query to only return what is between the parenthesis ... Full Name
0
Comment
Question by:jamesh1031
[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
1 Comment
 
LVL 4

Accepted Solution

by:
zveljkovic earned 500 total points
ID: 21788169
Hi. I didn't quite understand You but i think this is what are You looking for:
SELECT substring(
      FieldName,
      CHARINDEX( '(' , FieldName) + 1,
      CHARINDEX(')' , FieldName) - CHARINDEX( '(' , FieldName) - 1
) as FULLNAME
FROM TableName

substring is function which takes 3 parameters:
1. Is expression (string,field,..) from which to return a portion of it
2. is a number of characters from where to start a new string
3. is a number of characters where to end a new string

charindex is a function which returns a position of first parameter within second.
So for 2nd parameter of substring we say find us a parenthesis ( charindex ) and add 1 to that position to not include '(' in result. Similar for 3rd parameter.

NOTE:
1. This was tested in Microsoft Sql Express 2005 (can't guaranty that it will work right away in other DB's, but you could always look for string functions in their documentation)
2. This works only if they are only one open and closed parenthesis in the field.

Hope that helps,
Zlax
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

691 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