如果计数的百分比差异小于1%,则停止包裹

时间:2017-02-17 17:25:50

标签: sql-server-2008 ssis package percentage

我有一个每周运行的套餐,但如果计数差异超过1%则需要停止。

这是我的查询以获得2个计数的百分比:

USE MandatedReporting 
DECLARE @a AS float 
DECLARE @b AS float 
declare @c as float 

SET @a = (  SELECT Row_Count 
            FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] WITH(NOLOCK) 
            WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3' 
                  AND RunDate = (   SELECT MAX(RunDate) AS RunDate 
                                    FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] AS ThisWeeksData WITH(NOLOCK) 
                                    WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3')) 

SET @b = (  SELECT Row_Count 
            FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] WITH(NOLOCK) 
            WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3' 
                  AND RunDate = (   SELECT MIN(RunDate) AS RunDate 
                                    FROM [MandatedReporting].[dbo].[DCFS_Weekly_File_Row_Count] AS ThisWeeksData WITH(NOLOCK) 
                                    WHERE TableName = 'MandatedReporting.dbo.MATCH_WEEKLY_V3' 
                                    AND  ABS(DATEDIFF(DD,GETDATE(),CAST(RunDate AS DATETIME))) < 10)) 

set @c = (@a-@b) *100.0/@b SELECT @c as 'Count'

SQL Server 2008 感谢

1 个答案:

答案 0 :(得分:1)

您正在寻找条件拆分。在Execute SQL Task中执行存储过程后,需要将输出存储在变量中,然后根据输出实现条件拆分。

enter image description here

只是不是写出文件而只是结束你的数据流,否则如果你想要核选项,你可以抛出错误或在存储过程中做同样的事情:

begin
    raiserror('Foo Bar',16,1)
end