Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip Out Data from Field 1

Status
Not open for further replies.

sila

Technical User
Aug 8, 2003
76
0
0
GB
Hi
I hope someone can help me with this problem.

In the query below there may be some ForeName1 fields where there is a name e.g. Joseph (Joe). How can I use the query to strip out any instances where there is a name in brackets and leave the main name only as I need to put this into a url?

Thanks

<code>
(@MemberID as integer)
AS
SELECT ForeName1 + '_ ' + Surname AS Name FROM dbo.Members
WHERE MemberID = @MemberID
RETURN
</code>
 
Easiest way would be to just take the characters up to the opening parenthesis:

Code:
SELECT LTRIM(RTRIM(CASE WHEN forename1 LIKE '%(%' THEN LEFT(forename1, CHARINDEX('(', forename1) - 1) ELSE forename1 END)) + '_' + surname AS name
FROM members

--James
 
Alternatively
Code:
select 
CASE WHEN charindex('(', forename1) > 0 THEN rtrim(left(forename1, charindex('(', forename1)-1)) 
	ELSE rtrim(forename1)
END as Forename1
from @members

"I'm living so far beyond my income that we may almost be said to be living apart
 
Thanks that worked a treat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top