仅当SSIS中存在记录时如何继续

时间:2016-11-08 12:02:37

标签: ssis

对于此图表:

SSIS Package

“获取分数文件”脚本获取文件列表并将其放入用户变量文件列表(数据类型对象)。该列表将显示在“查找分数文件”循环中,并将处理列表中的每个项目。

我需要它才能运行,如果他们的文件有。如果“获取分数文件”脚本返回NO对象,我希望Package成功结束。我怎么告诉它这样做?

由于

1 个答案:

答案 0 :(得分:1)

在"获得分数文件"试试这段代码

declare @bundleDates table (
    BundleDate date,
    BundleID int,
    RunningNo int
)

insert into @bundleDates
select
    BundleDate,
    BundleID,
    row_number() over (order by (select null))
from NonRoomBundle
where BundleDate is not null order by BundleDate asc

declare @NonRoomBundle table (
    StayDate date,
    BundleDate date,
    BundleID int
)

declare
    @tmpBundleDate date,
    @tmpBundleID int,
    @tmpRunningNo int

declare cur cursor local for select BundleDate, BundleID, RunningNo from @bundleDates
open cur
fetch next from cur into @tmpBundleDate, @tmpBundleID, @tmpRunningNo
while @@fetch_status = 0
    begin
        if exists (select RunningNo from @bundleDates where RunningNo = @tmpRunningNo + 1)
            begin
                declare @currBundleDate date, @nextBundleDate date
                set @currBundleDate = @tmpBundleDate
                set @nextBundleDate = (select BundleDate from @bundleDates where RunningNo = @tmpRunningNo + 1)

                insert into @NonRoomBundle
                select
                    StayDate,
                    BundleDate,
                    BundleID
                from NonRoomBundle
                where
                    StayDate is null
                    and BundleID = @tmpBundleID

                union

                select
                    StayDate,
                    BundleDate,
                    case
                        when StayDate < @currBundleDate then BundleID
                        when StayDate >= @currBundleDate then @tmpBundleID
                    end as BundleID
                from NonRoomBundle
                where
                    StayDate is not null
                    and year(StayDate) <= year(@currBundleDate)
                    and month(StayDate) <= month(@currBundleDate)
                    and StayDate < @nextBundleDate
            end
        else
            begin
                insert into @NonRoomBundle
                select
                    StayDate,
                    BundleDate,
                    BundleID
                from NonRoomBundle
                where
                    StayDate is null
                    and BundleID = @tmpBundleID

                union

                select
                    StayDate,
                    BundleDate,
                    case
                        when StayDate < @tmpBundleDate then BundleID
                        when StayDate >= @tmpBundleDate then @tmpBundleID
                    end as BundleID
                from NonRoomBundle
                where
                    StayDate is not null
                    and year(StayDate) >= year(@tmpBundleDate)
                    and month(StayDate) >= month(@tmpBundleDate)
            end

        fetch next from cur into @tmpBundleDate, @tmpBundleID, @tmpRunningNo
    end
close cur
deallocate cur


select * from @NonRoomBundle

在SSIS中,您应该使用bool类型

再创建一个变量(files_present)

现在在每个循环之前的优先约束表达式中使用files_present变量检查是否存在任何文件`(如果存在真实文件则不存在文件)