对于amountB为null或0的测试用例,选择amountA的最简单方法是什么?
DECLARE @amountA float;
DECLARE @amountB float = 3.33;
select coalesce(@amountA, @amountB)
SET @amountA = 0.00;
select coalesce(@amountA, @amountB)发布于 2020-04-13 19:56:15
你只是在找
DECLARE @amountA float;
DECLARE @amountB float = 3.33;
select coalesce(nullif(@amountA, 0), @amountB);
SET @amountA = 0.00;
select coalesce(nullif(@amountA, 0), @amountB);或者像我在评论中所说的那样使用CASE表达式或IIF()函数。
https://stackoverflow.com/questions/61195574
复制相似问题