SQL Shortel Abandoned Calls Query

293 views Asked by At

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

2

There are 2 answers

0
Linger On BEST ANSWER

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
5
Ramesh On

Try this:

 SELECT IF(EXITREASON = 7, 1, 0) AS CallsAbandoned 
FROM   QUEUECALL 

SQL FIDDLE : http://sqlfiddle.com/#!2/56a1d/1