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)
 Select entire string after the second brack

Author  Topic 

NickC
Yak Posting Veteran

68 Posts

Posted - 2012-08-07 : 07:45:36
we have a table which basically shows the user then the change so

(n campbell) status change
(john smith) name modified
(\gem\chris campbell) updated rows

I want to get teh data after the brackets? I ve used left, right and substring before but dont think they will work. Any ideas hoping its quick and easy :)

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-07 : 07:49:41
You can use the stuff function like this:
SELECT STUFF(YourCol,1,CHARINDEX(')',YourCol),'');
Go to Top of Page

NickC
Yak Posting Veteran

68 Posts

Posted - 2012-08-07 : 07:51:00
thats some gr8 .... stuff :)
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-07 : 07:57:48
And no pun intended, right?
Go to Top of Page

vijayan.vinu3
Starting Member

19 Posts

Posted - 2012-08-22 : 08:13:17
That was a very nice query Sunita. I tried it using the Right function as follows:


Select RIGHT(Value, (CHARINDEX(')', Reverse(Value)) - 2)) As Status From Ex


But, STUFF was used so well in your query. It hadn't even crossed my mind to use STUFF. Very Nice!!
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-22 : 09:55:35
On the other hand, I tend to use STUFF when that is the best approach and even when it is not the simplest or most straightforward :)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-22 : 10:10:23
SELECT SUBSTRING(YourCol, CHARINDEX(')', YourCol) + 1, LEN(YourCol));



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -