如果表为空,如何返回失败 [英] How to return a failure if a table is empty
问题描述
使用 SQL Server 2005,但仍使用 DTS.我需要添加一个步骤来检查表是否为空,如果是,则以某种方式使该步骤失败.检查表是否为空很容易:
Using SQL Server 2005, but still using DTS. I need to add a step to check if a table is empty, and somehow fail the step if it is. It's easy checking if the table is empty:
Select count(*) from source_table
但是返回 0 也是成功的.如果它是 0,我想要一个失败(以便我可以分叉到不同的选项,给我们发电子邮件,跳过一些步骤).
But returning 0 is a success, too. If it is 0, I want a failure (so that I can fork to a different option, email us, skip some steps).
推荐答案
我没有使用 DTS.它已在 SSIS 中解决,但回想起来,我本可以在 DTS 中做类似的事情.
I didn't use DTS. It was resolved in SSIS, although, looking back, I could have probably done something similar in DTS.
第 1 步:选择计数并将该计数保存到变量的数据流任务.选择计数需要一些工作:
Step 1: A data flow task that selects count and saves that count to a variable. The select count took a bit of work:
select cast(count(*) as integer) as Row_Count from MyTable
然后数据流任务的输出是一个脚本组件,它是一个目的地,有一个输入列作为 ROW_COUNT,我的 ReadWriteVariables 作为 TableCount(在步骤 2 中用作输入的变量)
and then the output of the data flow task was a script component that was a destination and had an input column as that ROW_COUNT, and my ReadWriteVariables as TableCount (the variable that was used as input in step 2)
第 2 步:评估该计数并在计数为 0 时失败的脚本任务,否则成功.从中分叉是一条成功路线和一条失败路线.
Step 2: A script task that evaluates that count and fails if the count was 0, succeeds otherwise. Forking from this is a success route and a failure route.
这篇关于如果表为空,如何返回失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!