User People Tagged For Orgs =========================== This script runs from the `OrgSearch BlueToolbar`. It shows each person in the search results and the name of the current user's tag they are in along with the organization in the OrgSearch they are a member of. It will also display tags shared with the user. The recommended name is ``UserPeopleTaggedForOrgs`` Use the following code to Create the SQL Script. See :doc:`../CreateSqlScript`. .. code-block:: sql SELECT t.OwnerName, LinkForNext = '/Person2/' + CONVERT(VARCHAR(25), p.PeopleId), Name = p.Name2 , TagName = t.Name, LinkForNext = '/Org/' + CONVERT(VARCHAR(25), o.OrganizationId), o.OrganizationName FROM TagPerson tp JOIN Tag t ON t.Id = tp.Id JOIN dbo.People p ON p.PeopleId = tp.PeopleId JOIN dbo.CurrOrgMembers(@orgids) om ON om.PeopleId = p.PeopleId JOIN dbo.Organizations o ON o.OrganizationId = om.OrganizationId WHERE (EXISTS( -- my tags SELECT NULL FROM dbo.Users u WHERE u.UserId = @userid AND u.PeopleId = t.PeopleId) OR EXISTS( -- tags shared with me SELECT NULL FROM dbo.Users u JOIN dbo.TagShare ts ON ts.PeopleId = u.PeopleId AND ts.TagId = t.Id WHERE u.UserId = @userid ) ) AND TypeId = 1 -- personal tag ORDER BY p.Name2, t.Name