SQL Server Check for IsNull and for Zero

前端 未结 4 1817
离开以前
离开以前 2021-02-07 18:59

I have the following:

set @SomeVariable = @AnotherVariable/isnull(@VariableEqualToZero,1) - 1 

If @VariableEqualToZero is null it substitutes t

4条回答
  •  无人及你
    2021-02-07 19:30

    SET @SomeVariable = @AnotherVariable / COALESCE(
            CASE 
                 WHEN @VariableEqualToZero = 0 THEN 1
                 ELSE @VariableEqualToZero
            END, 1) - 1
    

提交回复
热议问题