Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.69 KB | None | 0 0
  1. SELECT
  2.     UserProfileKey
  3.    ,Name
  4.    ,OrganizationId
  5. FROM
  6.     (
  7.     SELECT
  8.         up.UserProfileKey
  9.        ,up.Name
  10.        ,uo.OrganizationId
  11.        ,ROW_NUMBER() OVER ( PARTITION BY uo.OrganizationId ORDER BY uo.DateCreated DESC )
  12.     FROM
  13.         dbo.UserOrganizations uo
  14.         JOIN dbo.v_UserProfileSummaries up
  15.         ON uo.UserProfileKey = up.UserProfileKey
  16.     WHERE
  17.         EXISTS
  18.         (
  19.             SELECT
  20.                 1
  21.             FROM
  22.                 org.UserPermissions up
  23.             WHERE
  24.                 up.OrganizationId = uo.OrganizationId
  25.                 AND up.UserProfileKey = uo.UserProfileKey
  26.                 AND up.PermissionId = 1
  27.         )
  28.     ) x;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement