Home > SSIS Best Practices > SSIS – Pass a variable to a OLE DB Source in a Data Flow

SSIS – Pass a variable to a OLE DB Source in a Data Flow

Continue from SSIS – Use “Foreach Loop Container” and pass a variable to a OLE DB Source in a Data Flow.

Step 2: Create a data flow step, into which we are going to pass a variable

image

Step 3: Create an OLE DB Source, Destination and a Data Conversion

image

Step 4: In the OLE DB Source Editor, write a SQL query.

Notice the WHERE clause, WHERE    M.TIME_DAY_GEN_ID = cast( ? as date ).

The question mark ? indicates that we need a parameter for this query.

Attention: when writing SQL query in this editor, always start with a simple query. The editor is not very sophisticated SQL editor. Complex SQL queries will confuse the editor.

image

Step 5: Click the Parameters… button.

In the Set Query Parameters windows, add a parameter by setting Parameter0 under Parameters, and User::vLoopDate under Variables.

Continue to finish the Column mappings.

image

We are done now.

If you open the Advance Editor for the OLE DB Source, you will see this in the Component properties tab.

Notice the ParameterMapping and the SQLCommand properties.

image

Advertisement
Categories: SSIS Best Practices
  1. Greg Kern
    August 26, 2011 at 8:04 pm | #1

    Perfect, just what I neeeded.

  2. Siphiwe Khuzwayo
    September 29, 2011 at 10:36 am | #2

    Hi,

    How would I go about passing a variable to an ADO.Net Source, for example Teradata. I would like to query teradata using a variable to return a specified query result.

    Been struggling to get this work, help would be appreciated.

  3. Sherry
    September 30, 2011 at 11:28 pm | #3

    Hi,

    I’ve answered your question in a new blog,

    SSIS #101 – Use expressions to pass parameters to ADO.NET Source

    Hope it helps.

    Sherry

  4. Megha
    January 27, 2012 at 5:28 pm | #4

    getting below error,
    ……where s.iso_country = cast( ? as varchar)

    Any sugesstions?

    TITLE: Microsoft Visual Studio
    ——————————

    Parameters cannot be extracted from the SQL command. The provider might not help to parse parameter information from the command. In that case, use the “SQL command from variable” access mode, in which the entire SQL command is stored in a variable.

    ——————————
    ADDITIONAL INFORMATION:

    Syntax error, permission violation, or other nonspecific error (Microsoft SQL Server Native Client 10.0)

    ——————————
    BUTTONS:

    OK
    ——————————

  5. Sherry Li
  1. August 27, 2011 at 3:24 am | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 25 other followers