Search code examples
mysqlsqlreporting-servicescaseshoretel

SQL Shortel Abandoned Calls Query


I am tring to query a table and it doesnt seem to be working. can anyone assist?

SELECT     ExitReason AS CallsAbandoned
FROM         queuecall
WHERE     (ExitReason = 7) THEN
                  (ExitReason = 1 ELSE
                  (ExitReason = 0)))

The deninition or outcome i am looking for is:

if {ExitReason} = 7 THEN 1 ELSE 0

I am not sure how complete the right query.

Thanks, Arron


Solution

  • The following is what you are looking for:

    SELECT CASE WHEN ExitReason = 7 
           THEN 1 
           ELSE 0 
           END AS CallsAbandoned 
    FROM queuecall
    

    Or if you are wanting a count of the result of the CASE then try the following:

    SELECT SUM(CASE WHEN ExitReason = 7 
           THEN 1 
           ELSE 0 
           END) AS CallsAbandoned 
    FROM queuecall