0

I have a user table, a role table that holds roleID and name, and a userrole table that has roleID and userID. Users can have multiple roles, so there could be multiple records returned for my select query. Is there a way that I can combine each roleID into a single row with a new column added for the additional roleID if it exists, either through a sql proc or in VB? I have a gridview that I will use for role management, it has 3 columns for roles, each with a checkbox that allows adding or deleting a role.

1
  • You should separate display logic from database schema. retrieve your data "as is" then recreate new data source object (eg. new DataTable) Commented Dec 13, 2013 at 3:55

1 Answer 1

4

Don't store multiple items in a single database column; you're violating first normal form, which is not good database design.

In your case, you could create a View that aggregates your multiple roles into a single "column" (comma delimited), and then base your gridview's datasource on the new View, instead of the base table.

You could do the same thing through a stored procedure.

Sign up to request clarification or add additional context in comments.

2 Comments

I actually did not want to delimit them into a single column, rather add an additional column onto the row only if the user has multiple roles. I do see your point and I want to keep it normalized.
A view or a stored proc would still probably be your solution Bob

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.