?
Solved

How do I select only the value that is between parenthesis

Posted on 2008-06-15
1
Medium Priority
?
188 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 2000 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

770 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