Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Remove part of string
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MikeSaunders
Starting Member

11 Posts

Posted - 07/04/2013 :  10:39:23  Show Profile  Reply with Quote
Hello,

I have a table with records that sometimes has extra descriptions between ():

EG:

name
mark (good guy)
eveline
jacob
tim (short guy)

Now i want to show only the name without the description.

Does someone knows a way to do this on a efficient way?

Mike

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/04/2013 :  11:01:37  Show Profile  Reply with Quote
Here is an example of how you can do this
select left(name,isnull(nullif(charindex('(',name),0),len(name)+1)-1)

Edited by - James K on 07/04/2013 11:02:32
Go to Top of Page

MikeSaunders
Starting Member

11 Posts

Posted - 07/04/2013 :  11:08:53  Show Profile  Reply with Quote
Hi James,

Thanks!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 07/05/2013 :  02:17:40  Show Profile  Reply with Quote
Also
STUFF(name,charindex('(',name+ '('),LEN(name),'')

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 07/05/2013 02:18:03
Go to Top of Page

ScottPletcher
Aged Yak Warrior

USA
550 Posts

Posted - 07/05/2013 :  11:31:57  Show Profile  Reply with Quote
SELECT LEFT(name, CHARINDEX('(', name + '(') - 1)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000