我有以下几点:

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


如果@VariableEqualToZero为null,它将替换为1。如果@VariableEqualToZero = 0,也需要它替换为1。我该怎么做呢?

最佳答案

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

10-08 08:15