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
 General SQL Server Forums
 New to SQL Server Programming
 Trimming results
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jodders
Starting Member

United Kingdom
39 Posts

Posted - 08/08/2013 :  05:28:12  Show Profile  Reply with Quote
Morning all,

I have set of data which has starts with the later "ABC\Bert" or "XYZ\Ernie" and would like to trim it so that anything after the "\" shows in my sql statement. I was thinking of doing a left trim but annoying, there are results in my table that already have data with out the "ABC\" or "XYZ\" in . Any advice on how to make these changes?

Cheers

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 08/08/2013 :  05:44:32  Show Profile  Reply with Quote
DECLARE @str VARCHAR(30) = 'ABC\Bert'
SELECT SUBSTRING( @str, CHARINDEX( '\', @str)+1, 30)


--
Chandu
Go to Top of Page

jodders
Starting Member

United Kingdom
39 Posts

Posted - 08/08/2013 :  05:53:16  Show Profile  Reply with Quote
Thanks chandu, works great
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 08/08/2013 :  06:17:08  Show Profile  Reply with Quote
SELECT STUFF(@str,1, CHARINDEX( '\', @str),'')


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

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 08/12/2013 :  01:20:55  Show Profile  Reply with Quote
quote:
Originally posted by jodders

Thanks chandu, works great


Welcome

--
Chandu
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.05 seconds. Powered By: Snitz Forums 2000