Solved

How do i unconcatenate a string in SQL?

Posted on 2006-06-11
4
427 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now