Aggregate returns zero value

  • Can you please help me resolve this issue:

    I have a temp table called temp_phone_interval, when I run this query:

    select max(currdate) as rpt_date, sum(ivr2q) as total_calls, sum(q2assagt+q2agt)as ans_calls, sum(q2assagt+q2agt+qabn)/sum(ivr2q) as svc_level,

    sum(qabn) as abn_calls,sum(qabn)/sum(ivr2q) abn_rate from temp_phone_interval where m_menu in(1,4)

    I get the following result:

    rpt_date total_callsans_callssvc_levelabn_callsabn_rate

    2008-01-10 00:00:00334328020

    Issue : I cannot figure out why the calculation for Svc_level & abn_rate is showing zero when both the numerator and denominator have values..

    Help please !!

  • pushalydan (12/11/2008)


    Can you please help me resolve this issue:

    I have a temp table called temp_phone_interval, when I run this query:

    select max(currdate) as rpt_date, sum(ivr2q) as total_calls, sum(q2assagt+q2agt)as ans_calls, sum(q2assagt+q2agt+qabn)/sum(ivr2q) as svc_level,

    sum(qabn) as abn_calls,sum(qabn)/sum(ivr2q) abn_rate from temp_phone_interval where m_menu in(1,4)

    I get the following result:

    rpt_date total_callsans_callssvc_levelabn_callsabn_rate

    2008-01-10 00:00:00334328020

    Issue : I cannot figure out why the calculation for Svc_level & abn_rate is showing zero when both the numerator and denominator have values..

    Help please !!

    All of your calculated values are integer. You can perform an implicit CAST like this:

    select max(currdate) as rpt_date,

    sum(ivr2q) as total_calls,

    sum(q2assagt+q2agt) as ans_calls,

    sum(q2assagt+q2agt+qabn)*1.00/sum(ivr2q) as svc_level,

    sum(qabn) as abn_calls,

    sum(qabn)*1.00/sum(ivr2q) abn_rate

    from temp_phone_interval

    where m_menu in(1,4)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Hint:

    SELECT 333/334

    ,333.0/334.0;

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply