Comma Delimited String

I have a string in SYBASE 11.5x that varies in length at any given time overall.  As well, the individual values in the string can vary in length also.  The only thing that remains the same is the comma delimiting between values.  For example, one string may read
(John, Dave,Betty) and the next read (Joe, Brian), etc.  How can I strip each value out the string between the commas to assign them to variables??
wcampb_ellAsked:
Who is Participating?
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.

wcampb_ellAuthor Commented:
Edited text of question.
0
ahoorCommented:
All you can do is use a while statement.
But you won't be able to have all the values in variables at the same time.
So, open a while loop, fill a variable with a value, then do something with it, then go back in the loop and overwrite the variable with the new value.

Example:

declare ...

select @string = 'John,Dave,Betty'
,        @comma = 0

while @comma > 0
begin
     select @comma = charindex(',',@string)
     
     if @comma > 0 -- comma exists
     begin
        select @name = substring(@string,1, @comma -1)
        select @string = substring(@string,@comma + 1, 255)
    end
    else      -- last time
    begin
        select @name = @string
   end

   -- now do something with @name

end

Arjan
0

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
wcampb_ellAuthor Commented:
I thought this was the way to do it, but wasn't sure - your answer just solidifies my decision to run a loop!!
0
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
Sybase Database

From novice to tech pro — start learning today.