hemtros
5/14/2020 - 10:41 PM

Example of Partition

							 select
  u.*
from
(
  select
   'RecordToUse' = row_number() over
    (
        partition by UniversalId
        order by case when domain = 'CTL' then 1 else 99 end,
        min(UserId)
    )
  , UserId
  from dbo.Users u with (nolock)
  group by UniversalId, UserId, Domain
) t
join dbo.vw_Users u on (u.UserId = t.UserId)
where t.RecordToUse = 1