Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- UserProfileKey
- ,Name
- ,OrganizationId
- FROM
- (
- SELECT
- up.UserProfileKey
- ,up.Name
- ,uo.OrganizationId
- ,ROW_NUMBER() OVER ( PARTITION BY uo.OrganizationId ORDER BY uo.DateCreated DESC )
- FROM
- dbo.UserOrganizations uo
- JOIN dbo.v_UserProfileSummaries up
- ON uo.UserProfileKey = up.UserProfileKey
- WHERE
- EXISTS
- (
- SELECT
- 1
- FROM
- org.UserPermissions up
- WHERE
- up.OrganizationId = uo.OrganizationId
- AND up.UserProfileKey = uo.UserProfileKey
- AND up.PermissionId = 1
- )
- ) x;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement