I am trying to help a coworker optimize a database that was created many moons ago. It's a list of documents, and along with a document title and other relevant info, each document has a category and a subcategory, and in fact can have more than one of each. The original person building this database decided that it would be a good idea to put comma-delimited lists of categories and subcategories in columns (one column for each) in the same table as the documents. This has led to some issues that you would probably expect from such a setup.

I've decided to "clean up" this database by moving all the categories and subcategories into their own tables, where they will have ID numbers (this is done), then add a relational table to join each document ID with all the category and subcategory IDs it belongs to.

My problem is that I can't join the comma-delimited columns in the documents table to the category or subcategory tables, so I'm having trouble adding all the values to the new table. Other than making the changes by hand, is there an easier way to insert the appropriate values into my new table?