Description
This query assumes that you have assigned rep by putting their GoldMine userid in key4. It shows the one most recent history for each assigned contact. In this case the rep is ‘DCS’
SELECT
c1.contact
,c1.company
,c1.city
,c1.STATE
,c1.country
,CASE LEFT(ch.rectype,2)
WHEN 'CO' THEN 'Call Out'
WHEN 'CI' THEN 'Call In'
WHEN 'CC' THEN 'Call Back'
WHEN 'CM' THEN 'Returned Message'
WHEN 'MO' THEN 'Email Out'
WHEN 'MI' THEN 'Email In'
WHEN 'A ' THEN 'Appointment'
WHEN 'N ' THEN 'Next Action'
WHEN 'O ' THEN 'Other Action'
WHEN 'L ' THEN 'Form'
ELSE
ch.rectype
END Activity
,CONVERT(VARCHAR(10),ch.ondate,101) DATE
,ch.REF
,ch.notes
,ch.accountno
,c1.accountno
FROM
conthist ch (NOLOCK)
JOIN contact1 c1
ON ch.accountno=c1.accountno
WHERE
srectype IN ('C','A','E','M' )
AND LEFT(c1.key4,3) = 'DCS'
AND ch.recid IN
(SELECT TOP 1 recid
FROM conthist
WHERE
(accountno=ch.accountno)
AND srectype IN ('C','A','E','M','T')
AND userid = 'DCS'
ORDER BY
ondate
,recid DESC)
ORDER BY
c1.company