我有两列ActivityCount和ParentValue.我创建了一个表达式:
ROUND((ActivityCount / ParentValue) / 100,16) * 100
Run Code Online (Sandbox Code Playgroud)
但问题是它返回NULL了一些列,我想替换NULL为0.我似乎无法找到答案.
小智 8
ISNULL(ParentValue) || (ParentValue == 0) ? 0 : ROUND(ISNULL(ActivityCount) ? 0 : ActivityCount / ParentValue / 100,16) * 100
Run Code Online (Sandbox Code Playgroud)
ISNULL(ParentValue) || (ParentValue == 0)
? 0
: ROUND((ISNULL(ActivityCount)
? 0
: ActivityCount / ParentValue) / 100
, 16) * 100
Run Code Online (Sandbox Code Playgroud)
如果ParentValue字段是NULL或有Zero,则不必执行计算,因为您将遇到Divide by Zero错误.因此,只需返回0即可退出表达式.
如果ActivityCount是field NULL,则在执行计算之前将其替换为零.
COALESCE如果可能的话,我建议在源查询上使用零替换NULL值和计算.