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 2005 Forums
 Transact-SQL (2005)
 extracting a part of a statement

Author  Topic 

zion99
Posting Yak Master

141 Posts

Posted - 2008-10-16 : 10:08:53
Hi,

I need to remove some part from a statement-

DECLARE @loc varchar (100)
set @loc = 'opt - ABC Trading (India)'
select substring(@loc,1,LEN(@loc)-LEN(SUBSTRING(@LOC, CHARINDEX('(',@loc), CHARINDEX(')',@loc,len(@loc)-3))))


Basically, i need to remove all the characters contained in the parenthesis & including the parenthesis.
Output - 'opt - ABC Trading'

Can anybody suggest a better option (performance wise) than what i have written?
Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-16 : 10:13:15
select left(@loc,charindex('(',@loc)-1)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-16 : 10:14:08
Also
select stuff(@loc,charindex('(',@loc),charindex(')',@loc),'')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -