alter view dbo.vAssetUserPerson as
select
	t.NodeId,
	t.[User],
	t.PersonId,
	PersonManagerId
from (
	select
		u.intNodeId NodeId,
		pk.txtValue [User],
		u.iPersonId PersonId,
		u.liPersonManagerPersonId PersonManagerId,
		row_number() over (partition by u.intNodeId order by u.u) rn
	from (
		select
			n.intNodeId,
			p.iPersonId,
			p.liPersonManagerPersonId,
			1 u
		from tblNode n
			join tPerson p on lower(p.sPersonAdGuid)=lower(n.txtLDAPGUID) and p.dPersonRemoved is null
		where n.lintClassId=7

		union all

		select
			n.intNodeId,
			p.iPersonId,
			p.liPersonManagerPersonId,
			2
		from tblNode n
			join vPropertyKind pk on pk.lintNodeId=n.intNodeId and pk.intKindCode=74
			join tPerson p on lower(p.sPersonPersonalNumber)=lower(pk.txtValue) and p.dPersonRemoved is null
		where n.lintClassId=7

		union all

		select
			n.intNodeId,
			p.iPersonId,
			p.liPersonManagerPersonId,
			3
		from tblNode n
			join vPropertyKind pk on pk.lintNodeId=n.intNodeId and pk.intKindCode=54
			join tPerson p on lower(p.sPersonLogin)=lower(pk.txtValue) and p.dPersonRemoved is null
		where n.lintClassId=7

		union all

		select
			n.intNodeId,
			p.iPersonId,
			p.liPersonManagerPersonId,
			4
		from tblNode n
			join vPropertyKind pk on pk.lintNodeId=n.intNodeId and pk.intKindCode=46
			join tPerson p on lower(p.sPersonEmail)=lower(pk.txtValue) and p.dPersonRemoved is null
		where n.lintClassId=7
		) u
		join vPropertyKind pk on pk.lintNodeId=u.intNodeId and pk.intKindCode=5
	) t
where rn=1