splitting a string

i am trying to convert a field containing a string into 3 fields.

the string is of the format

alphanumeric decimal [comma] decimal


Moyo Island -8.259857,117.573064

i want it split in 3 eg.

Moyo Island    |   -8.259857   |   117.573064
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ephraim WangoyaCommented:
Ephraim WangoyaCommented:

Look at the section
3. Parse the list into a set
that's awkward, your list is not delimited - you could really have done with a delimiting character between the place name and the co-ordinates.  The delimiter mustn't appear in the place name, in this case you have a space which can also appear in the place name.

A function reading back through the string could be written to strip out the two numbers.

Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

tommarshallandrewsAuthor Commented:
Thanks guys.

My idea was to try and strip all the numbers & commas out to get the place name then strip the characters to get a comma separated string and try and pot that into 2 columns.

Would that make sense? If so any idea how??

Ephraim WangoyaCommented:
try it this way
declare @temp varchar(max)
declare @var1 varchar(max), @var2 varchar(50), @var3 varchar(50)

set @temp = 'Moyo Island -8.259857,117.573064'

set @temp = REVERSE(@temp)

set @var1 = REVERSE(SUBSTRING(@temp, 1, CHARINDEX(',', @temp, 1)-1))

set @temp = SUBSTRING(@temp, LEN(@var1), LEN(@Temp) - LEN(@var1) +1)
set @var2 = REVERSE(SUBSTRING(@temp, 1, CHARINDEX(' ', @temp, 1)-1))
set @var3  = REVERSE(SUBSTRING(@temp, LEN(@var2), LEN(@Temp) - LEN(@var2) +1))

select @var1, @var2, @var3

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This will do it.

DECLARE @T1 varchar(200) = 'Moyo Island -8.259857,117.573064'

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.