Note that there are some explanatory texts on larger screens.

plurals
  1. POT-SQL: Opposite to string concatenation - how to split string into multiple records
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2647/split-string-in-sql">Split string in SQL</a> </p> </blockquote> <p>I have seen <a href="https://stackoverflow.com/questions/tagged/concatenation+sql">a couple of questions related to string concatenation</a> in SQL. I wonder how would you approach the opposite problem: splitting coma delimited string into rows of data:</p> <p>Lets say I have tables:</p> <pre><code>userTypedTags(userID,commaSeparatedTags) 'one entry per user tags(tagID,name) </code></pre> <p>And want to insert data into table</p> <pre><code>userTag(userID,tagID) 'multiple entries per user </code></pre> <p>Inspired by <a href="https://stackoverflow.com/questions/314682/which-tags-are-not-in-the-database">Which tags are not in the database?</a> question</p> <p><strong>EDIT</strong></p> <p>Thanks for the answers, actually more then one deserves to be accepted but I can only pick one, and the <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314917">solution presented by Cade Roux</a> with recursions seems pretty clean to me. It works on SQL Server 2005 and above. </p> <p>For earlier version of SQL Server the solution <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314833">provided by miies</a> can be used. For working with text data type <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314866">wcm answer</a> will be helpful. Thanks again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload