3

How can I pass parameters in an OLE DB Source to call a table-valued function like:

select * from [dbo].[udf_test](?, ?)

When doing so, I am getting the error:

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 form variable" access mode, in which the entire SQL command is stored in a variable. Syntax error, permission violation, or other nonspecific error (Microsoft SQL Native Client)

Is there another solution than "SQL command from variable"?

Sven

3 Answers 3

3

You can use the SQL Command from Variable, it is relatively straightforward. You could build the SQL statement to pass to the Source using a Script transform to edit the variable which holds the SQL. So for example you'd set up a variable called strSQL and make the value

select * from [dbo].[udf_test](?1, ?2)

And then in the script component, replace the ?1 and ?2 values with the parameters you want to pass using string manipulation methods.

It's a little more work in the package but works well in my experience.

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

3 Comments

But why has the OLE DB Source Editor a button for setting Parameters?
Ah of course...having a week off work has frazzled my brain! It will depend on what data source you are connecting to. If you are connecting to SQL Server, then you should be able to pass the parameters via the OleDb source. It looks like you are connecting to SQL Server though, so I'm wondering if the call to the function needs to be wrapped in a Stored Procedure rather than called directly via T-SQL. Can you try that? I'll add that the method I mentioned above is a good work-around for Data Readers.
Yes, wrapping the Table-Valued Function in a Stored Procedure does work! Thanks!
0

This is a little bit of a workaround but it works pretty well. What we do is create a stored procedure called SetVar that will take an input parameter and assign it to a declared out parameter.

Create a procedure called SetVar in the OLE DB source database. It assigns @inputVar to @outVar

CREATE PROC SetVarInt
    @inputVar INT ,
    @outVar INT OUTPUT
AS
BEGIN
    SELECT @outVar = @inputVar;
END

In the SSIS OLE DB source use this SQL:

DECLARE @param1 INT;

EXEC [dbo].[SetVarInt] @inputVar = ?, -- int
    @outVar = @param1 OUTPUT -- int

SELECT * FROM [dbo].[GetByKey](@param1)

If nothing happens, the optimizer may have optimized the task away (check package execution log). In this case I will add the following to the end of the OLE DB source SQL, and connect this output to a RowCount task into a dummy variable.

SELECT 1 Done;

Comments

0

If you want to keep it simple, and just have the query in the OLDDB source without using other tricks, you can achieve that by writing the entire T-SQL code needed to get it done e.g.

declare @var1 as int = ?;
declare @var2 as datetime = ?;

select * 
from [dbo].[udf_test](@var1, @var2);

Doing it like that you do not need to have a separate task in SSIS to build the query and assign the parameteres, it all stays in the same place, and therefore easier to write, and even more important easier to understand by the person who will need to support this after you.

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.