如果表为空,如何返回失败
使用SQL Server 2005,但仍然使用DTS。我需要添加一个步骤来检查表是否为空,如果是,则以某种方式使该步骤失败。检查表是否为空很容易:
Select count(*) from source_table
但返回 0 也是成功的。如果它是 0,我想要失败(这样我就可以分叉到不同的选项,给我们发电子邮件,跳过一些步骤)。
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
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
返回-1怎么样?
如果您确实想引发错误,可以使用 RAISERROR 来就这样做:
what about returning -1 ?
If you really want to raise an error, you can use RAISERROR to do just that :
您可以除以计数结果:
You can divide by count result:
我没有使用DTS。它在 SSIS 中得到了解决,尽管回想起来,我可能可以在 DTS 中做类似的事情。
步骤 1:数据流任务选择计数并将该计数保存到变量中。选择计数需要一些工作:
然后数据流任务的输出是一个脚本组件,它是目标,并且有一个输入列作为 ROW_COUNT,我的 ReadWriteVariables 作为 TableCount(在步骤 1 中用作输入的变量) 2)
步骤 2:评估该计数的脚本任务,如果计数为 0,则失败,否则成功。由此分叉,有成功路线,也有失败路线。
I didn't use DTS. It was resolved in SSIS, although, looking back, I could have probably done something similar in DTS.
Step 1: A data flow task that selects count and saves that count to a variable. The select count took a bit of work:
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)
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.