Menu
Reply To Topic Topic: Useful DNN SQL Scripts
:
Posted By Deleted User on 7/31/2018 10:03 PM
Test to see if a UserID is in a particular role or is an administrator. The following example will test UserID=306 to see if they are either in the "Newsletter Manager" role or an administrator. You would change those two parameters to match your needs. And it would be much better if you put this into a stored procedure that passed in those two parameters instead of typing them in the SQL script. This will return "HasRoleYes" if the user is in the roles, and "HasRoleNo" if they are not in the roles. SELECT CAST(CASE WHEN COUNT(*) > 0 THEN 'HasRoleYes' ELSE 'HasRoleNo' END AS nvarchar(15)) AS 'HasRole' FROM UserRoles INNER JOIN Roles ON UserRoles.RoleID = Roles.RoleID INNER JOIN Users ON UserRoles.UserID = Users.UserID WHERE Roles.Rolename IN ('Newsletter Manager', 'Administrator') AND Users.UserID = '306'
Username:
Security Code:
CAPTCHA image
Enter the code shown above in the box below.
Subject:
RE: Useful DNN SQL Scripts
Message:
Smilies

Submit

Cancel
Subscribe:
Topic Review