Solved

How do i unconcatenate a string in SQL?

Posted on 2006-06-11
4
469 Views
Last Modified: 2008-02-07
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
0
Comment
Question by:bdietz
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
pootle_flump earned 500 total points
ID: 16882107
Hi

There are more functions and methods than you could ever need here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

I think I use a version of the first one (the table returning function) as I recall. Very easy to use.

HTH
0
 
LVL 11

Expert Comment

by:pootle_flump
ID: 16882115
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
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16882667
Hi bdietz,

another option is to use dynamic sql

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

Aneesh R!
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16883133
I would also use the function suggested by pootle_flump, as it protects against sql injection, and is more readable also.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now