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 Everything to Right of Character

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2013-05-16 : 11:36:09
I need to be able to remove everything to the right of the first colon in a field.

For example:

1234:TEST would be just TEST

1234:1234:TEST would be 1234:TEST

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-16 : 11:39:48
perhaps you meant to remove everything to the left of the first colon?

Declare @x varchar(100)
set @x='1234:1234:TEST'
SELECT substring(@x,6,len(@x))

Cheers
MIK
Go to Top of Page

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-05-16 : 12:12:32
[code]substring(@value,charindex(':',@value)+1,len(@value))[/code]
not tested

djj
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-05-16 : 18:07:28
It looks like you're removing everything to the left of the first colon.

If so, djj55 has provided the code for that.
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-17 : 21:23:34
quote:
Originally posted by djj55

substring(@value,charindex(':',@value)+1,len(@value))

not tested

djj


Or you can do this:
[CODE]
SELECT STUFF(@value,1, charindex(':'(@value), '');
[/CODE]
Go to Top of Page
   

- Advertisement -