I have a SSIS package that runs daily as a step in the job agent, 21 of 42, and last week I added a Sequence Container to the package to run two Execute SQL Tasks. Both of the tasks use the merge statement with an update and insert specified using a CTE
as the source. The target is a table I add records to in the same package in the prior Execute SQL Task. The Precedence Constraint value for the new Sequence Container is Success. There is another Sequence Container after the one I add that loads and process the cube.
The Merge statements execute as expected in the query window in Management Studio and if I manually execute the sequence container in the SSIS package, (right click Execute Container).
When the step runs in the job agent it is as if the sequence container is ignored as nothing is updated, the cube however is processed. I thought maybe the job agent was running an old version of the package so I reselected the package with no change in
the result. I have no options checked in the Job Step Properties. The job step does not error. There are no errors in any of the logs. The IsolationLevel is set to Serializable on each container in the SSIS Package.
I have other steps in the same Job Agent package that include the Merge statement but they run as a Transact- SQL Script.
I have looked on-line but do not see any similar issues.
Below is one of the code bits where I use the merge statement.
with pay_Cte as(
Select dh.WorkDate
, case when ne.CJOBTITLE = 'Material Handler' then sum(dh.DailyHours * coalesce(ad.Rate,0)) else 0 end as DirectPay
, case when ne.CJOBTITLE <> 'Material Handler' then sum(dh.DailyHours * coalesce(ad.Rate,0)) else 0 end as SupportPay
, case when ne.CJOBTITLE = 'Material Handler' then sum(dh.DailyHours ) else 0 end as DirectHours
, case when ne.CJOBTITLE <> 'Material Handler' then sum(dh.DailyHours) else 0 end as SupportHours
from dbo.DCDailyHours dh
join dbo.Nova_Employee ne on ltrim(rtrim(ne.CEMPID)) = dh.EMPID
left outer join dbo.v_ADPRates ad on cast(ad.empno as numeric(15,0)) = cast(ne.cempid as numeric(15,0))
Where CGROUP7 like '%DISTWI%'
and dh.WorkDate = cast(DATEADD(dd,-1,current_timestamp) as DATE)
--and dh.WorkDate = '08/25/2013'
group by dh.WorkDate , ne.CJOBTITLE
)
, summary_cte as(
Select 7 as division_id, WorkDate, SUM(DirectPay) as directpay, SUM(SupportPay) as supportpay, SUM(directhours) as DirHours, SUM(supportHours) as SupHours
from pay_Cte
group by WorkDate
)
--Select division_id, workdate, dirhours, directpay, suphours, supportPay from Summary_cte
merge dbo.DailyTotals as tr
using (Select division_id, workdate, dirhours, directpay, suphours, supportPay from Summary_cte ) as ct
on cast(tr.datadate as date) = cast(ct.workdate as date) and tr.division_id = ct.division_id
When matched then
Update
Set tr.DirectHours = coalesce(Tr.DirectHours,0) + ct.DirHours
,tr.SupportHours = coalesce(tr.SupportHours,0) + ct.SupHours
, tr.DirectPay = coalesce(tr.DirectPay,0) + ct.DirectPay
,tr.SupportPay = coalesce(tr.SupportPay,0) + ct.SupportPay
when not matched by target
then Insert(Datadate, Division_id, directhours, directpay, supporthours, supportpay) values(ct.workdate, ct.Division_id,ct.dirhours, directpay, ct.suphours, ct.supportPay);