Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesI have a column that has text delimited by a percent sign that I wish to turn into rows. Example: A column contains ROBERT%CAMARDA, I want to turn that into two rows, one row with ROBERT and antoher row with CAMARDA. I will have source rows that have zero, one, or many percent sign delimiters that will correspond to that many rows (One percent sign will create 2 rows, 2 percent signs will create 3 rows and so forth). Any thoughts? TIA Rob
Post Follow-up to this messagercamarda (rcamarda@cablespeed .com) writes: > I have a column that has text delimited by a percent sign that I wish > to turn into rows. > Example: > A column contains ROBERT%CAMARDA, I want to turn that into two rows, > one row with ROBERT and antoher row with CAMARDA. > I will have source rows that have zero, one, or many percent sign > delimiters that will correspond to that many rows (One percent sign > will create 2 rows, 2 percent signs will create 3 rows and so forth). Have a look at an article on my web site: http://www.sommarskog.se/arrays-in-sql.html. Specifically, look at "List-of-strings" and "Unpacking a table column". You did not say which version of SQL Server you are using. The article is written for SQL 2000. SQL 2005 provides a new operator CROSS APPLY which is good for the column bit. In SQL 2000, you will have to run it row by row. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pr...oads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodin...ions/books.mspx
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread