web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

need a quick query to know how many times we’ve contacted a customer

(0) ShareShare
ReportReport
Posted on by

Hello,

With the Dynamics CRM database, I need a quick query to know how many times we’ve contacted a customer (in the last 30 days, 90 days, 180 days, etc).

At first, I thought there might be a SQL view of "Activity History" that could be leveraged but cannot find anything.

Any ideas?

Thanks

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Something like this maybe:

    SELECT COUNT(DISTINCT  ActivityId) FROM

    ActivityPartyBase

    WHERE PartyId = <accountid>

    Although, this will likely give you all activities (incoming/outgoing, phone calls/emails/letters/etc), so you may want to join in ActivityPointerBase(using activityid) and filter by ActivityTypeCode and some of those directon code fields (EmailDirectionCode etc)

  • Zach Mast Profile Picture
    70 on at

    Here is a working query to get you started:

    select ap.[Subject], ap.[Description], email.DirectionCode
    --select count(*)								--If you just want the count
    from activitypointer ap
    join account on ap.RegardingObjectId = account.accountid
    left join Email on ap.activityid = email.activityid
    where ap.activitytypecode in (4202)				--Emails, update this to have the desired activity types		
    and account.name = 'A Datum Corporation'		--Update to your account name, or use accountid instead
    --and email.directioncode = 1					--1 = Outgoing, 0 = Incoming


  • Rod C Profile Picture
    on at

    Thanks for both replies. I tried your queries even with no where clause and only see a few rows. So, perhaps, there is something else in our system created by one of our vendors. I will keep investigating.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    SELECT COUNT(*) FROM

    ActivityPartyBase

    WHERE PartyId = 'GUID_OF_ACCOUNT'

    Should give you the total number of interactions with activities for that account

  • Rod C Profile Picture
    on at

    Thanks for your suggestions. I think I have more research to understand which tables / filtered views to join together.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans