I have an excel file that has a column that contains a number of comma-separated IDs for each row, and each row contains another column of text, e.g.
IDs Text
1 This is a row of text
2,3 Another row of text
4,5,6 More text in this row
I need to insert the text into the a database so that each ID in the first column is split into its own row, and the text is inserted for each ID that it is associated with.
The result in the database would be, e.g.
ID Text
1 This is a row of text
2 Another row of text
3 Another row of text
4 More text in this row
5 More text in this row
6 More text in this row
Is there any functionality in Excel 2010 or Sql Server 2008 which can do this for me?
Otherwise, is there functionality in Excel which can split the comma-separated values into rows? I know there is a tool which can split them into new columns, but I need rows. If I can get them into rows, I can do a copypasta to get the text associated with the corresponding IDs.
You could write a simple little macro that will generate the insert statements for you, and then you could just copy and paste those into management studio:
Obviously, there are more efficient ways to write the loops and split logic, but for a quick little utility to generate the SQL, this should work well.
UPDATE: Added a “+ j” to the column mapping for the output, otherwise you will stick each string on top of the previous one, oops 🙂