You can accomplish this with a denormalization query... I've written a detailed blog on how to do this here:
http://www.transio.com/content/how-d...able-using-sql
The basic requirement is that you need a finite number of properties to display as columns.
Here's an example of how your query might look using your schema:
Obviously, you'll have to change "ROLEx" for the names of your roles.
Cheers!
Code:
SELECT
ua.ID,
MAX(CASE WHEN st.name = 'ROLE1' THEN 1 ELSE 0 END) AS ROLE1,
MAX(CASE WHEN st.name = 'ROLE2' THEN 1 ELSE 0 END) AS ROLE2,
MAX(CASE WHEN st.name = 'ROLE3' THEN 1 ELSE 0 END) AS ROLE3,
MAX(CASE WHEN st.name = 'ROLE4' THEN 1 ELSE 0 END) AS ROLE4
FROM
UserAccounts AS ua
INNER JOIN UserAccountRoles AS uar ON ua.ID = uar.UserAccountID
INNER JOIN UserRoles AS AS ur ON ur.ID = uar.UserRoleID
GROUP BY ua.ID
Bookmarks