vinisha9
vinisha9

Reputation: 91

Selectively Execute Dataflow tasks in SSIS based on a If else condition

I want to create a SSIS package which will have two data flow tasks. If today's date is startdate of the Month it should execute one dataflow task(which actually has a month end report), else then it should execute another dataflow task(which is a weekly report). Can anyone please let me know how to attain this one.

Thanks,

Upvotes: 2

Views: 1755

Answers (1)

Jonathan Porter
Jonathan Porter

Reputation: 1556

1.) Create a variable of datatype boolean in the package scope. I named mine startDate in this example.

enter image description here

2.) Create a script task with two precedent constraints. One going to the data flow task when it's the beginning of the month and the other when it's false. enter image description here

3.) Edit the script task and add the startDate variable into ReadWriteVariables. enter image description here

4.) Click on "Edit Script" and insert the following into the method (you can uncomment the message box to make sure it works correctly when you execute the package) and don't forget to save:

DateTime value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

        if (DateTime.Today == value)
        {
            Dts.Variables["User::startDate"].Value = bool.Parse("True");
        }
            Dts.Variables["User::startDate"].Value = bool.Parse("False");

        //MessageBox.Show(Dts.Variables["User::startDate"].Value.ToString());

5.) After that, all you have to do is edit the precedence constraints going to each DFT. enter image description here enter image description here

Upvotes: 1

Related Questions