I'm inserting data into a SQL database with a foreign key on the table.
The input script takes from a staging table to update a live table with new records.
The input tool uses this query to retrieve the data
select c.AbsenceStartDate,
c.AbsenceEndDate,
c.AbsenceDays,
c.AbsenceHours,
c.AbsenceReasonCode,
c.AbsenceReasonLDesc,
c.AbsenceCertTypeLDesc,
c.AbsenceTypeCode,
c.AbsenceEntryStatus,
c.AbsenceEntryStatusDesc,
c.EmployeeID,
c.CreationDate,
c.ModifiedDate
From (select a.* , b.EmployeeID
from [HR].[StagingAbsence] a
Join HR.Employee b on a.EmployeeNumber = b.EmployeeNumber) c
Where not Exists (Select EmployeeID, AbsenceStartDate, AbsenceEndDate
From HR.Absence d
Where c. EmployeeID = d.EmployeeID
and c.AbsenceStartDate = d.AbsenceStartDate
and c.AbsenceEndDate = d.AbsenceEndDate)
Where EmployeeID is the foreignKey.
The append Existing on the Output tool is giving me the foreignkey constraitn error.
Is there a way to get around this? Better way of achieving this?