How To Loop Through A Comma Delimited String In SQL

Looping through a comma delimited string in SQL is easy to do, but can take a few minutes to write and test the scripts, which I never really have the time for, so now I have a permanent home for this script for me to reference.

Here’s what I setup this script for (you can easily modify it):

I have a registration form that accepts Degree Types(e.g., MD, PHD, MS, etc.) to be  freely typed in a textbox (I know, I hate this too) so that doctors don’t have to select them from a listbox, which I think is much easier, but the issue is obvious – you can’t just insert a string of comma-delimited degrees into the database, that is if your database is properly structured (many to many relationship) anyway, so I needed to accept the string into my Stored Procedure and then break the comma-delimited string up so that I can insert it into the database. Anyhow, feel free to copy and adjust this script as needed. (more…)

Learn More