Link to home
Start Free TrialLog in
Avatar of bdietz
bdietz

asked on

How do i unconcatenate a string in SQL?

I have a string such as:

322,992,124,643,233

being passed from an ASP form to a ms sql stored procedure.  i want too pull out each number and insert them into the same column, but different rows

322
992
124
643
233

How can i do this?  THanks
ASKER CERTIFIED SOLUTION
Avatar of pootle_flump
pootle_flump

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pootle_flump
pootle_flump

To be more complete - you could use the first function like this:

INSERT INTO MyTable (MyField)
SELECT      Data
FROM dbo.Split('322,992,124,643,233', ',')

HTH
Avatar of Aneesh
Hi bdietz,

another option is to use dynamic sql

EXEC('Insert into urTable (UrColumn)  SELECT  '+@AboveString +'')
 

Aneesh R!
I would also use the function suggested by pootle_flump, as it protects against sql injection, and is more readable also.