Split string in SQL

I have the following input string

@instring = '02542577,02028900,01228136'

This has to split like @instring =  ( '2542577', '2028900', '1228136' )  in Sql server .  

I know there is better way to split it to table of values and use it in sql. but the above mentioned formatted string has to passed to third party application.
vensaliAsked:
Who is Participating?

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

x
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.

John GobertEnterprise Systems ConsultantCommented:
I'm sure there are many different opinions out there but I'd suggest building a function that you can call to do this.  I've used the method described here:  CodeProject - Most Practical Split Function

Let's assume you name the function fn_split when you create it in your database.  Using it would be as simple as:

[dbo].[FN_SPLIT] (@instring, ',')

If this doesn't work for you just reply back with more requirements and I'll try to help.
Vitor MontalvãoMSSQL Senior EngineerCommented:
SET @instring = '(''' + REPLACE(@instring,',',''',''') + ''')'

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
HuaMin ChenProblem resolverCommented:
Try
declare @str varchar(30),
@prt varchar(30),
@prt2 varchar(30),
@prt3 varchar(30),
@pos int,
@pos2 int,
@pos3 int

set @str = '02542577,02028900,01228136'
set @pos=charindex(',',@str)
set @pos2=charindex(',',@str,@pos+1)
set @pos3=len(@str)

set @prt=substring(@str,1,@pos-1)
set @prt2=substring(@str,@pos+1,@pos2-1-@pos)
set @prt3=substring(@str,@pos2+1,@pos3-@pos2)

print @prt
print @prt2
print @prt3

Open in new window

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
Microsoft SQL Server

From novice to tech pro — start learning today.