Need to look up descriptions from a list of IDs

I have a field in my Customers table called Skills.  The customer could have more than one skill so I store the Skill_IDs as a comma separated list in the Skills field.  I also have a Skills table with Skill_IDs and Skill_Descriptions.  After retrieving the comma separated list of Skill_IDs, I need to display them as the Skill_Descriptions.  What is the best approach for this?

My approach was to spit the list into an array, then dynamically create a SQL statement on the Skills table to retrieve the descriptions whilst navigating through the array of Skill_IDs.  However, I am worried about security using this approach so I really need a way of passing the IDs to an sproc to retrieve the Skill_Descriptions.  Note the comma separated list could be anything - eg. 1,2,3 or 3,4 or 4,5,8.
Who is Participating?
Personally,  I always find lists of things packed into one field to be a pain!    So if I had control over the data model,  I would implement many-to-many relationships like this via an intersection table e.g. CustomerId, SpecId

Assuming this is not an option,  I further assume that your security concern is related to SQL injection attacks?

If so,  why don't you just modify your current approach,  split the list on the client,   verify that each Id in the list is purely numeric,  then query the database either directly or using a procedure that accepts a single Id as a parameter and returns the description.

Of course, you could implement all of that in the stored procedure and pass in the string.   The important thing is to split the list and verify that each member is a legally formatted Id of a specialty.   That should prevent malicious attack.
Scott PletcherSenior DBACommented:
>> What is the best approach for this? <<

A Customer_Skills table, the "standard" intersection table when you have a potentially multi-valued column (a column should be a SINGLE value, NOT a list).

Required here anyway, since you will need additional info about THAT SPECIFIC COMBINATION of values:
    1) when did this specific customer acquire this specific skill?
    2) when did this specific customer LOSE this specific skill? (for example, accreditation or license lost)
    3) restrictions on this skill? / subskill
    4) etc.

NO WAY you want to store all that in the base Customers table.
Lorna70Author Commented:
Great - thanks guys.  We are implementing the first phase as a really simple one but you're both absolutely right - I need to change my data model to cope with future expansion :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.