Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsReportsReportsFiltering Member Report by RoleFiltering Member Report by Role
Previous
 
Next
New Post
6/17/2007 9:39 AM
 

Okay, I found the following SQL script online (THANK YOU) but I wish to modify it so it returns the registered uses who are not assigned any other roles.  The part I modified was to look at the RoleID in UserRoles, sum them up and return only those queries that = 1.

I am a novice in SQL and could really use the help, the code is below and my additions are in red.  Thanks!!

 

SELECT Users.Username, Users.LastName, Users.FirstName, Users.Email,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 26
) As Street,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 27
) As City,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 30
) As Zip,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 31
) As Home,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 32
) As Cell,

(SELECT UserRoles.UserId, SUM(UserRoles.RoleId)
FROM UserRoles
GROUP BY UserRoles.UserID
HAVING SUM(UserRoles.RoleId)= 1) as Role

FROM Users INNER JOIN
UserPortals ON Users.UserID = UserPortals.UserId
INNER JOIN
UserRoles ON Users.UserID = UserRoles.UserID

WHERE UserPortals.PortalId = 0 AND
Role = 1

ORDER BY Users.Lastname

 
New Post
6/18/2007 9:36 PM
 

I'm not quite sure what the purpose of your post is, are you having a specific problem with the query you posted?

However, I do think there is a slightly easier way to do what you want, see my adjusted query below:

SELECT Users.Username, Users.LastName, Users.FirstName, Users.Email,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 26
) As Street,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 27
) As City,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 30
) As Zip,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 31
) As Home,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 32
) As Cell,

FROM Users INNER JOIN
UserPortals ON Users.UserID = UserPortals.UserId
INNER JOIN
UserRoles ON Users.UserID = UserRoles.UserID

WHERE UserPortals.PortalId = 0 AND
(NOT EXISTS (SELECT UserRoles.* FROM UserRoles WHERE UserRoles.UserID = Users.UserID))

ORDER BY Users.Lastname


Andrew Nurse
DotNetNuke Core Team Member and Reports Module Project Lead
Microsoft Certified Professional Developer

 
New Post
6/19/2007 5:26 AM
 

Ok, I think I may have a solution for you:

SELECT Users.Username, Users.LastName, Users.FirstName, Users.Email,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 26
) As Street,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 27
) As City,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 30
) As Zip,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 31
) As Home,

(SELECT PropertyValue FROM UserProfile WHERE
UserProfile.UserID = Users.UserID AND
UserProfile.PropertyDefinitionID = 32
) As Cell

FROM Users

WHERE (EXISTS (SELECT UserPortals.* FROM UserPortals WHERE UserPortals.UserId = Users.UserId AND UserPortals.PortalID = 0)
AND (EXISTS (SELECT UserRoles.* FROM UserRoles WHERE UserRoles.UserId = Users.UserId AND UserRoles.RoleId = 1))
AND (NOT EXISTS (SELECT UserRoles.* FROM UserRoles WHERE UserRoles.UserId = Users.UserId AND UserRoles.RoleId <> 1))

ORDER BY Users.Lastname

I'm not a SQL guru, so someone else may be able to give you a more performant query, but that seems like it should work. Basically it first filters out users who are NOT a member of Role #1 (Registered Users, I think, but you can check and change as necessary) and then filters out users who are ALSO a member of another role. With 3 subqueries it might be a little slower, so someone with more SQL experience may have a better suggestion, but it should work for you.

In this situation, where you are trying to bring back one record from a main table (Users) and then select certain records out of sub-tables (UserProfile, UserPortals, UserRoles, etc.) I find it easier to use sub-queries than fiddle with OUTER JOINs, but there may be a performance hit.

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsReportsReportsFiltering Member Report by RoleFiltering Member Report by Role


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out