我用过这样的东西。实际上,我用我想要搜索的项目的所有 guid(在我的情况下为帐户和联系人)构建了一个表 var,然后我查询 AcitivtyParty 以获取他们参与活动的所有活动 - 然后转到 Activity 以获取详细信息。
Declare @account_guid varchar(200)
Select @account_guid = 'insert some guid here'
Declare @GUIDS as Table(id varchar(200), fullname varchar(200), objecttype char(2))
Declare @ActivityIds as Table(id varchar(200))
--grab all guids we need activities for
Insert Into @GUIDS
Select contactid, fullname, 'C'
From FilteredContact
Where accountid = @account_guid
UNION ALL
Select accountid, [name], 'A'
From FilteredAccount
Where accountid = @account_guid
--find all activities where the account/contact are referred to
Insert Into @ActivityIds
Select activityid
From FilteredActivityParty fap
Join @GUIDS g on g.id=fap.partyid
Group By activityid
Select *
From FilteredActivityPointer fap
Join @ActivityIds a on fap.activityid = a.id
Where statecode<>2 --hide canceled items