SQL Server Performance

SQL Query.

Discussion in 'T-SQL Performance Tuning for Developers' started by sqlchat, Mar 22, 2004.

  1. sqlchat New Member

    I have table with the following structure (Ms-Access DB).

    CallID AutoIncrement
    CallDescription Varchar
    CallClosed Boolean
    CallCharged Boolean
    CallCancelled Boolean
    CreatedDate DateTime

    Now i need a query which lists the total no of calls,no of calls closed, no of calls charged and no of calls cancelled for given date range.Is it possible to do this in a single query.I tried using Group By function but couldn't succeed though,Now i'm using three queries to achieve this.Thanks for your replies.
  2. ChrisFretwell New Member

    Yes it is. here is one way

    select createddate, count(*), sum(case when callclosed = 1 then 1 else 0 end) as callsclosed,
    sum(case when CallCharged = 1 then 1 else 0 end) as CallsCharged,
    sum(case when CallCancelled = 1 then 1 else 0 end) as CallsCancelled
    from table
    group by createddate

Share This Page