declare @startdate as datetime
declare @enddate as datetime
set @startdate = '2010-07-29'
set @enddate = '2010-07-29'
select case max(ccdr.callednumber) when '5900' then 'NX' else 'NX' end as company
--,max(ccdr.originatorDN) -- see below, tried SUM and COUNT
,isnull(sum (case when ccdr.originatorDN <> '' then 1 else 0 end),0) -- tried this
from db_cra.dbo.ContactCallDetail ccdr
inner JOIN ContactQueueDetail cqd ON cqd.sessionID = ccdr.sessionid
WHERE ccdr.startDateTime >= DATEADD(dd, 0, DATEDIFF(dd, 0, @startdate))
AND ccdr.startDateTime < DATEADD(dd, 0, DATEDIFF(dd, 0, @enddate +1))
AND applicationName = 'Main'
AND ccdr.callednumber IN ('5900') and originatorDN = '11111'
group by ccdr.originatorDN
having count(ccdr.originatorDn) > 1
I get
NX 2
I should get
NX 1
|