英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论