SQL Server Forums
Profile | Register | 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 Everything to Right of Character
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Brittney10
Posting Yak Master

USA
152 Posts

Posted - 05/16/2013 :  11:36:09  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 05/16/2013 :  11:39:48  Show Profile  Reply with Quote
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

Edited by - MIK_2008 on 05/16/2013 11:40:21
Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
306 Posts

Posted - 05/16/2013 :  12:12:32  Show Profile  Reply with Quote
substring(@value,charindex(':',@value)+1,len(@value))

not tested

djj
Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
335 Posts

Posted - 05/16/2013 :  18:07:28  Show Profile  Reply with Quote
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

547 Posts

Posted - 05/17/2013 :  21:23:34  Show Profile  Reply with Quote
quote:
Originally posted by djj55

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

not tested

djj


Or you can do this:

SELECT STUFF(@value,1, charindex(':'(@value), '');
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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