Within a stored procedure I need to loop the following table:
SELECT *
FROM dbo.UsersInRoles
INNER JOIN Application_Users ON UsersInRoles.AppUserID = Application_Users.AppUserID
WHERE (UsersInRoles.ApplicationId = @ApplicationId)
AND (UsersInRoles.RoleId = @CurrentRoleId)
AND (Application_Users.LastLogin < @StartDate)
And for each record that is looped I need to perform this update:
UPDATE UsersInRoles
SET UsersInRoles.RoleId = @DenyRoleId
WHERE (UsersInRoles.ApplicationId = @ApplicationId)
AND (UsersInRoles.RoleId = @CurrentRoleId)
If there is a better way to perform this then I'm open to suggestions. Basically the 1st query does a filter based upon the INNER JOIN
to determine which records need to be updated. Then those filtered records are looped and updated with a new RoleID
.