Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL2008
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 30 May '12 - 23:32


1 solution

Try this:
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
  Permalink  
Comments
jaipal0908 - 31 May '12 - 5:58
Thank you,its working
Nikfazan - 31 May '12 - 6:45
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 259
1 OriginalGriff 220
2 Mahesh Bailwal 159
3 CPallini 143
4 Maciej Los 140
0 Sergey Alexandrovich Kryukov 10,214
1 OriginalGriff 7,819
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 31 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid