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
 SQL Server Administration (2008)
 Susbtring Issue

Author  Topic 

Hoffmann
Starting Member

6 Posts

Posted - 2009-10-06 : 11:04:45
hi folks, sorry to bother you again, but I'm really stuck at this point...I have to import an address but I need to break the number from the street.

e.g: '5th avenue, 555' would end up as '5th avenue','555'.

I've searched a lot on the web and tried to use Substring, but I still didn't get it to work properly. Can somebody help me? Or gimme the link to where I could get help?

Thank you!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-06 : 11:32:21
First have a look at your data please.
I'm sure that '5th avenue, 555' is the most practicable version but which data combinations are also in your table.
Is there a way to tell us a condition on how to split the data so it fits to (nearly) all data?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-06 : 13:00:05
please post some more sample data andwhat the expected results would be

Whats '555' anyway?

Look at the hint link in my sig and post what it asks for



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Hoffmann
Starting Member

6 Posts

Posted - 2009-10-06 : 13:02:46
yeah, every number is after a " , "...always. I think it's pretty easy but I've not figured it out yet Oo
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-06 : 13:30:30
[code]

DECLARE @x varchar(255)

SET @x = '5th avenue, 555'

SELECT '"' + SUBSTRING(@x,1,CHARINDEX(',', @x)-1) + '"' AS Street
, '"' + SUBSTRING(@x,CHARINDEX(',', @x) + 2, LEN(@x) - CHARINDEX(',', @x) + 1) + '"' AS [Date?]


[/code]


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-07 : 02:13:08
If there is always a single comma

DECLARE @x varchar(255)

SET @x = '5th avenue, 555'

select PARSENAME(replace(@x,',','.'),2) , PARSENAME(replace(@x,',','.'),1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -