1

I am wanting to have a user enter the database path they will be using.

For Example: @SourceDB = DatabaseA.dbo.

I would then like to use the variables in a Data Flow or Execute SQL task.

My question: How do I reference the variables in these two tasks? Neither of these ways seem to be working for me:

SELECT Field1, Field2 FROM @SourceDB + tablename

or

"SELECT Field1, Field2 FROM " + @[User::SourceDB] + "tablename"

or

SELECT Field1, Field2 FROM ? tablename

1 Answer 1

1

You won't be be able to use it as a parameter ?. Others have tried to do that and run into what you're experiencing.

What I would do is define a variable, call it SourceQuery, data type of String, scoped at the package level. In the properties window for that variable (F4), change the EvaluateAsExpression property to True. Then use a formula in the expression like you have already specified. "SELECT Field1, Field2 FROM " + @[User::SourceDB] + "tablename"

Finally in your OLE DB Source, change the access mode to table or view to "SQL Command from variable" and then things should just work.

The one caveat to be aware of is that if the data types for these columns change, your SSIS packages will fail the Validation step.

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

Comments

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.