Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am using aspnetdb database.
I created the Users,Roles and assigned Roles to the Users.
Now I need a query to display UserId,Username for a particular RoleId.
For example,
I have a user ABC with some uniquekey1 and a Role with RoleName 'Admin' which assigned to user ABC and RoleId with some uniquekey2.
Now I want a query to fetch UserID,userName for a particular Role.

I think I am clear.
Please anyone help me.

Thank you,
Posted

1 solution

Try this:
SQL
SELECT        aspnet_Users.UserName, aspnet_Users.UserId
FROM          aspnet_Users INNER JOIN
              aspnet_UsersInRoles ON aspnet_Users.UserId = aspnet_UsersInRoles.UserId INNER JOIN
              aspnet_Roles ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId
WHERE        (aspnet_Roles.RoleName = 'admin')

Hope it help
 
Share this answer
 
v3
Comments
jaipal0908 31-May-12 5:58am    
Thank you,its working
Nikfazan 31-May-12 6:45am    
You are welcome, so accept it as solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900