Skip to content Skip to sidebar Skip to footer

Multiple Select Case Statements In Query For Shoretel Reports

I am trying to do a query that allow for multiple columns in a view. Any assistance would be helpful. SELECT queuecall1.StartTime, queuecall1.QueueName CASE WHEN ExitReason

Solution 1:

You need to do a separate case statement for each column:

SELECT  queuecall1.StartTime, 
        queuecall1.QueueName,
        CASEWHEN ExitReason = 7THEN1ELSE0ENDAS CallsAbandoned,
        CASEWHEN ExitReason = 1THEN1ELSE0ENDAS CallsAgent,
        CASEWHEN calltype = 1THEN1ELSE0ENDAS CallsInternal,
        CASEWHEN calltype = 2THEN1ELSE0ENDAS CallsExternal
FROM   (queuecall queuecall1 INNER JOIN connect connect1 
ON queuecall1.ConnectTableID=connect1.ID) INNER JOINcall call1 
ON connect1.CallTableID=call1.ID

This would give an output like:

StartTime | QueueName | CallsAbandoned | CallsAgent | CallsInternal | CallsExternal
----------+-----------+----------------+------------+---------------+---------------
 10:59    |  Queue1   |      1         |    0       |     1         |      0
 11:05    |  Queue1   |      1         |    0       |     1         |      0
 11:11    |  Queue1   |      0         |    1       |     1         |      0
 11:12    |  Queue1   |      0         |    0       |     0         |      1
 11:24    |  Queue1   |      0         |    1       |     0         |      1
 11:37    |  Queue1   |      1         |    0       |     0         |      1
 11:42    |  Queue1   |      0         |    1       |     0         |      0

Post a Comment for "Multiple Select Case Statements In Query For Shoretel Reports"