在SQL存储过程中处理NULL值的问题。

huangapple go评论62阅读模式
英文:

Problem with handling NULL values in an SQL procedure

问题

以下过程应该能够处理以下操作:
如果记录之间的差异为0,我们让其通过;如果没有数据或摘要文件,或两者都没有 - 我们终止它。

然而,如果当一切匹配时 DIFF_RECORDS 也为空,那么我们将终止作业。

我应该如何更改这里的逻辑以处理这种情况?

英文:

The following procedure should be able to handle the following action:
If the difference in records is 0, we let it pass; if there are no data or summary file, or neither - we terminate it.

However, if DIFF_RECORDS is also null when everything matches, we will then terminate the job.

How can I change the logic here to handle such a case?

答案1

得分: 1

应该颠倒IF表达式的顺序,首先检查@DIFF_RECORDS是否为NULL,然后分别检查长度。

IF @DIFF_RECORDS IS NULL
  THROW 51000, '没有新文件可加载', 0;

IF LEN(@DIFF_RECORDS) > 0
  THROW 51000, @DIFF_RECORDS, 0;
英文:

You should reverse the order of the IF expressions, first check for @DIFF_RECORDS being NULL and separately check the length.

IF @DIFF_RECORDS IS NULL
  THROW 51000, 'No fresh files to load', 0;

IF LEN(@DIFF_RECORDS) > 0
  THROW 51000, @DIFF_RECORDS, 0;

huangapple
  • 本文由 发表于 2023年6月26日 15:05:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定