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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Remove part of string

Author  Topic 

MikeSaunders
Starting Member

11 Posts

Posted - 2013-07-04 : 10:39:23
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-04 : 11:01:37
Here is an example of how you can do this
select left(name,isnull(nullif(charindex('(',name),0),len(name)+1)-1)
Go to Top of Page

MikeSaunders
Starting Member

11 Posts

Posted - 2013-07-04 : 11:08:53
Hi James,

Thanks!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-05 : 02:17:40
Also
STUFF(name,charindex('(',name+ '('),LEN(name),'')

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-07-05 : 11:31:57
SELECT LEFT(name, CHARINDEX('(', name + '(') - 1)
Go to Top of Page
   

- Advertisement -