Dynamics CRM 2011 のオンライン バージョンで FetchXML を使用して、今後 30 日から 60 日から 90 日以内に終了するテリトリー (テリトリーはアカウントで定義されます) ごとのすべての商談のリストを取得する方法はありますか?
テスト データベースに SQL を記述してこれを実行しようとしましたが、次の SQL を使用することで可能です。
select Territory.TerritoryId ,
(select count(OpportunityId) from Opportunity where Opportunity.AccountId = Account.AccountId and Account.TerritoryId = Territory.TerritoryId and EstimatedClosureDate < '12/12/2011') as OppIn30Days,
(select count(OpportunityId) from Opportunity where Opportunity.AccountId = Account.AccountId and Account.TerritoryId = Territory.TerritoryId and EstimatedClosureDate < '12/1/2012') as OppIn60Days,
(select count(OpportunityId) from Opportunity where Opportunity.AccountId = Account.AccountId and Account.TerritoryId = Territory.TerritoryId and EstimatedClosureDate < '12/2/2012') as OppIn90Days
from territory left outer join Account on Territory.TerritoryId = Account.TerritoryId --group by Territory.TerritoryId, Account.TerritoryId, Account.AccountId
-- TODO parameterization of query, etc.
SQL の結果は次のようになります。
Columns: TerritoryId|OpportunitiesClosingIn30Days|OpportunitiesClosingIn60Days
Data: US 5 1
Europe 1 4
Asia 4 5
外部結合がサポートされていないため、FetchXML を使用してこれを行うことは可能ですか?
商談に非表示のテリトリー フィールドを追加し、商談が作成されるたびに対応する取引先からテリトリーがコピーされるようにコードを記述すれば、役に立ちますか?