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
 Other SQL Server 2008 Topics
 select string

Author  Topic 

nord
Posting Yak Master

126 Posts

Posted - 2013-11-04 : 16:12:06
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-04 : 16:30:54
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 - 2013-11-05 : 08:39:58
Thanks
Go to Top of Page
   

- Advertisement -