I have a SQL table like the following
RoleId Roles
------------------------------------------
1 Administrators Viewers Users Managers
2 Administrators Viewers Managers
3 Administrators
4 Viewers
I need to get the RoleId's based on the roles. I have each role as a string.
So when I use the following query
SELECT *
FROM Roles
WHERE Roles like '%Administrators Viewers Managers%'
I get only the first two rows
RoleId Roles
--------------------------------------------------
1 Administrators Viewers Users Managers
2 Administrators Viewers Managers
But I need it to fetch the remaining rows too since it contains Administrators and Viewers.
I am actually using an Stored procedure to supply the roles as a parameter. So it is not always the same. Its dynamic. I cant use OR. I need a solution that will work for any parameter.
Is there a combination between IN and LIKE clause ?
Or how can I proceed
ROLES TABLE: roleID 1=Admin, roleID 2=ViewerPERMISSIONS TABLE: roleID=1, view=yes, admin=yes, edit=yes; roleId=2, view=yes, admin=no, edit=no. Then you would be able to do more complex queries.