88
Views
2
Comments
Solved
SQL query User and Roles List
Question
Application Type
Reactive

Hi All,

I am developing a User Management application, Where I have multiple role of single user. On a List page I need to show all Roles name which assigned to user. But with aggregate I am not able to do it.

I am trying to sql but not able to solve it.

Can anyone help me on that.


Thanks in advance.

2026-02-26 06-29-24
Rahul
 
MVP
Solution

Hi @Mark Joe ,

You can use below sql -

Select UM.[Id],UM.[Name],

       (

       select ','+RM.[Name]

       from {Role} as RM

       INNER JOIN {User_Role} on RM.[Id] = {User_Role}.[Role_Id] 

       for xml path('')) as RoleName

from {User} as UM

And this is the output structure.


In Addition you can added more attributes and filter condition in this sql.

Hope this will help you.


2023-05-24 12-18-44
Mark Joe

Thanks its work as expected. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.