views:

1009

answers:

1

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

+2  A: 

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.

revelator
But why has the OLE DB Source Editor a button for setting Parameters?
Sven Sönnichsen
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.
revelator
Yes, wrapping the Table-Valued Function in a Stored Procedure does work! Thanks!
Sven Sönnichsen