Using SQL command from variable in Data flow task

  • Hello,

    Here is my requirement. I need the ability to use one of the below two queries in my oledb command

    Query1: Select a1,b1,c1 from table1

    Query1: Select a1,b1,c1 from table2

    Note : both tables table1 and table2 have the same schema

    I build the query in a script task and populate a user variable. ( gvUserVar)

    gvUserVar could either have Query1 or Query2 based on some logic.

    Iam using 'SQL command from variable' in OLE Command Source ( in data flow task ) and have set the User::gvUserVar as the variable name.

    So far so good.

    Now i need to do some transformation of a1,b1,c1 before i move data to a file

    Issue: I do not get to see the source columns as output of the OLEDB Command souce. Is this because the query is being built at runtime?

    Also if i to transform or work with the column output from 'SQL command from variable' what do i need to do?

    Any help is appreciated.

    Thanks!

  • Yes, your query is being built at run time, so at design time there's no information to know to show you the columns, which makes it difficult for you to set it up correctly. (You could define the columns manually if you knew what to set.)

    Try it with your actual first query, instead of using a variable. When that is set up and working, change it back to use the variable.

    In general in SSIS, with anything computed such as a connection name or query string, set it up first with an actual fixed name, then change to use the variable when it's working. That allows SSIS to help you set things up, because it can access the object and know its characteristics.

  • I tried this with my actual query and the output file was correct. I then switched back to using my variable and received an error. The objects and characteristics of the columns are not available any more.

    I am using VS2008

  • At what point did you receive the error? (Run time or design time.)

    Have you made any modifications to the DelayValidation property?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Also, setting the default (design-time) value of the variable to be a valid query may help you get over this hurdle.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply