How to divide two numbers when one has zero values

  • This is my statement in my stored procedure:

    Select Count (EmployeeStatus) where  .... As 'Employed',

    Count(EmployeStatus) Where As 'Employeable',

    [Employed] /[Employeable]

     

    Employed has a zero records. and the division does not work.

    It could also be due to the fact that

    (Stored procedure fails becuase of the aliases I asigned to the EmployeStatus)

    Any clues?

     

  • ISNULL([Employed] /NULLIF([Employeable], 0), @ValueToIndicateDividingByZero)

    _____________
    Code for TallyGenerator

  • When can I use IIf (IsEmpty(Employed)) in sql server?

  • Hi

    For your purpose, ISNULL & NULLIF is enough. If you want to use function like IIF(x,y,z) in SQL, you can use (CASE WHEN ..... THEN ..... END). See BOL for this.

    Amit

  • Faye, there is no "IIf" in T-SQL. It's just another language with other commands and operators.

    Replacement for IIf you may find in the 1st reply of this topic.

    _____________
    Code for TallyGenerator

Viewing 5 posts - 1 through 4 (of 4 total)

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