Solved

How do i unconcatenate a string in SQL?

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Do we need servers??? 5 206
ESX 6.0 Best Practices for datastore size 5 124
VMWare environment audit 8 63
T-SQL: New to using transactions 9 46
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

791 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