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
 Other SQL Server 2008 Topics
 select string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nord
Posting Yak Master

126 Posts

Posted - 11/04/2013 :  16:12:06  Show Profile  Reply with Quote
Hi,
I need select two strings
for ex: transformer,toronto
I need string 1.before ','
2. after ','

first string I got it:select SUBSTRING(Vendor_Address3,0,CHARINDEX(',',Vendor_Address3,0)),but second I dont know
p.s:in second sometimes have space before word,how I can do it?
Thanks

James K
Flowing Fount of Yak Knowledge

3722 Posts

Posted - 11/04/2013 :  16:30:54  Show Profile  Reply with Quote
Use LTRIM and/or RTRIM to remove leading and trailing spaces. Like shown below:
SELECT LTRIM(RTRIM(LEFT(Vendor_Address3,CHARINDEX(',',Vendor_Address3+',')-1))),
	LTRIM(RTRIM(STUFF(Vendor_Address3,1,CHARINDEX(',',Vendor_Address3+','),'')))
Go to Top of Page

nord
Posting Yak Master

126 Posts

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