4

I am very new to SSIS and I am building a package which will import files. I have a Execute SQL Task which will execute a SQL statement which will return files that needs to be imported, but the files will need to go into different tables depending on which file is being imported.

I have 2 Data Flow Tasks in my foreach container but now based on the file type it needs to execute 1 of them

How can I achieve this?

enter image description here

EDIT

This is the query that will be executed:

SELECT ReconMedicalAidFile.fReconMedicalAidFileID,   ReconMedicalAidFile.fReconMedicalAidID, 
ReconMedicalAids.fMedicalAidID, ReconMedicalAidFile.fFileName, 
ReconMedicalAidFile.fFileLocation, ReconMedicalAidFile.fFileImportedDate, ReconMedicalAidFile.fNumberRecords, ReconMedicalAidFile.fUser, 
ReconMedicalAidFile.fIsImported
FROM ReconMedicalAidFile INNER JOIN
ReconMedicalAids ON ReconMedicalAidFile.fReconMedicalAidID = ReconMedicalAids.fReconMedicalAidID
WHERE (fIsImported = 0) AND (fNumberRecords = 0)

So the condition is based on fMedicalAidID

3
  • I assume you have multiple files, hence the ForEach loop. How are the file types recognized? By the extension? Commented Jun 17, 2015 at 8:12
  • I have a flag column in my table which will indicate which file is which Commented Jun 17, 2015 at 8:15
  • Please post sample data from your table Commented Jun 17, 2015 at 8:15

2 Answers 2

4

The dummy script approach: DummyScript

In the expressions for the two precedence constraints you evaluate a variable that is set either by the first SQL task or the script task. enter image description here

Now, the data will flow down one of the two data flow paths based on the value of the variable. The script task can be empty, or it can perform the logic needed to set the variable.

Sign up to request clarification or add additional context in comments.

Comments

1

I don't believe you will be able to do what you want in SSIS with the way your current package is designed.

An alternate approach:

  1. Add a Conditional Split task after the first Execute SQL task
  2. Split based on file type
  3. Create a separate ForEach Loop and Execute SQL task for each file type

5 Comments

Unable to add Conditional Split in the Control Flow, it can only be added in the Data Flow.
Is it perhaps possible to set a variable in the foreach that gets passed to the Data Flow and from there to do the split?
What are you doing with the result set from the first Execute SQL task?
I set it to a object type variable and that is where it should iterate through the results
You can use a dummy script task in place of a conditional split. Just use two outputs with expressions in the constraints.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.