I'm using SQL Server 2008 R2 Enterpriser, SSIS
So I'm running an ad hoc reporting command. To construct the query and return the output I created a stored procedure.
A Data Source in a Data Flow has its source set to a string variable, which composes the call to the Stored Procedure.
Inside the Stored Procedure, the select statements are joined to the dynamic where clauses.
At the end of the Stored Procedure is a call to sp_sqlexec to run the dynamic sql text.
When I run the SSIS package,i'm getting an error at the step where the Data Source is called toprovide the data. The error is:
"Incorrect syntax near the keyword 'LIKE'.".
If I take the stored procedure text from the variable it is and place it in SSMS, I'm able to run the command with no error.
I suspect the issue is that the DataSource cannot inspect the table layout of the output of this stored procedure. I did have to fool SSIS when creating the data flow by alterting the stored procedure so it ended with a Select statement that included all the columns of my output. When the DataFlow designer captured all the columns I reverted the stored procuedure so that sp_execsql was the last line again.
How can I do this at run-time? Somehow fool SSIS into getting the column information it needs but returning the data from sp_execsql and not a final select statement.