I have linked tables. Calls and Call Lines, both tables have a seperate ‘Call Type’ field, I am trying to get the number of calls and the number of call lines which were added on a certain date and then see the split for the types. The below query returns the number for each Call Line which was added, but shows a blank space for Calls which were added. Is there a way to use a link in a Group By?
x
SELECT COUNT(dbo.CallLines.kblCallLineID) AS "Total Calls", dbo.CallLines.ukblCallType AS "ukblCallType"
FROM (dbo.CallLines
LEFT OUTER JOIN dbo.Calls ON dbo.CallLines.kblCallID = dbo.Calls.kbpCallID)
WHERE dbo.CallLines.kblContactMethodID = 'PHONE' AND dbo.CallLines.kblAddedDate > '{%Yesterday Date YYYYMMDD%}' AND dbo.CallLines.kblAddedDate < '{%Current Date YYYYMMDD%}' GROUP BY dbo.CallLines.ukblCallType
This returns the following result:
TOTAL CALLS CALL TYPE
2
1 Purch
6 Qte FU
1 Sales -OB
1 Support
The first result of 2 are from calls not call lines, can I link these to show the type for these as well?
Advertisement
Answer
I think you want to count a column in Calls
, so the query should be:
SELECT COUNT(c.kblCallLineID) AS "Total Calls",
cl.ukblCallType AS "ukblCallType"
FROM dbo.CallLines cl LEFT OUTER JOIN
dbo.Calls c
ON cl.kblCallID = c.kbpCallID
WHERE cl.kblContactMethodID = 'PHONE' AND
cl.kblAddedDate > '{%Yesterday Date YYYYMMDD%}' AND
cl.kblAddedDate < '{%Current Date YYYYMMDD%}'
GROUP BY cl.ukblCallType ;
This will not eliminate the row, but from what you say, the count will be zero.