ISERROR

  • I have the following

    SELECT #callhandling2.client

    ,#callhandling2.daycat+' '+#callhandling2.timecat as [Category]

    ,Sum(#callhandling2.calls) as [Total Calls]

    ,[Calls Per 30 Mins] = Case

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekend 20:00-08:00' then if(iserror(Sum(#callhandling2.calls)/2208.0)),0,Sum(#callhandling2.calls)/2208.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekend 08:00-20:00' then Sum(#callhandling2.calls)/2208.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekday 20:00-08:00' then Sum(#callhandling2.calls)/5304.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekday 08:00-20:00' then Sum(#callhandling2.calls)/5304.0

    Else 'I dont know'

    End

    But have a problem with the if(iserror) bit of my case statement.

    Basically I want to say if there is a division by 0 error then NA or something similar

  • carl.meads (11/14/2011)


    I have the following

    SELECT #callhandling2.client

    ,#callhandling2.daycat+' '+#callhandling2.timecat as [Category]

    ,Sum(#callhandling2.calls) as [Total Calls]

    ,[Calls Per 30 Mins] = Case

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekend 20:00-08:00' then if(iserror(Sum(#callhandling2.calls)/2208.0)),0,Sum(#callhandling2.calls)/2208.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekend 08:00-20:00' then Sum(#callhandling2.calls)/2208.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekday 20:00-08:00' then Sum(#callhandling2.calls)/5304.0

    When #callhandling2.daycat+' '+#callhandling2.timecat='Weekday 08:00-20:00' then Sum(#callhandling2.calls)/5304.0

    Else 'I dont know'

    End

    But have a problem with the if(iserror) bit of my case statement.

    Basically I want to say if there is a division by 0 error then NA or something similar

    Wow, got a weird case of "deja-vu" here 😉


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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