A Microsoft platform for building enterprise-level data integration and data transformations solutions.
Yes. Use the SSIS variable to supply either:
- The entire SQL command, or
- The parameter values used by a single SQL command.
Because the OLE DB Source cannot branch logic itself, the choice of which query to run must be made outside the component and then passed in.
Two common patterns:
- SQL command from variable
- Create a string variable, for example
User::SqlToRun. - In a Script Task or Expression on the variable, set its value based on
User::InitialorMonthly, e.g.:- If
InitialorMonthly == "Initial"→"SELECT ..." - Else →
"SELECT ... WHERE ModifyDate BETWEEN ..."
- If
- In the OLE DB Source Editor, set Data access mode to SQL command from variable and select
User::SqlToRun. - The OLE DB Source will execute whatever SQL text is in that variable.
- Create a string variable, for example
- Parameterized SQL + variables
- Use a single parameterized query in the OLE DB Source, e.g. with
?placeholders. - Click Parameters and map each
?to SSIS variables (date range, flags, etc.). - Use SSIS expressions or other control-flow logic to set those variables based on
User::InitialorMonthly. - At run time, the same query runs, but with different parameter values.
- Use a single parameterized query in the OLE DB Source, e.g. with
If the logic truly requires different SQL shapes (different WHERE clauses, joins, etc.), pattern 1 (SQL command from variable) is the usual approach in a Data Flow.
References: