问题
all.
I am using stored procedures from linked server. I want to use the procedure in ole db source.
I wrote the query, which works in SSIS.
select ID,
LAST_NAME_ENG,
LAST_NAME_G,
FST_NAME_ENG,
FST_NAME_G,
BIRTHDATE
from openquery (linkedserver,
'exec [linkedserver].get_records @SESSION_ID = 12 , @SYSTEM = ''oCRM'', @ENTITY_NAME = ''CLIENT''
WITH RESULT SETS (([ID] [int] NOT NULL,
[LAST_NAME_ENG] [varchar](50) NOT NULL,
[LAST_NAME_G] [varchar](50) NOT NULL,
[FST_NAME_ENG] [varchar](50) NOT NULL,
[FST_NAME_G] [varchar](50) NOT NULL,
[BIRTHDATE] [date] NOT NULL))');
I can use it in SSIS ole db source and successfully get required data. But in the next step there is the problem:
I need to pass the parameter to the @SESSION_ID from SSIS instead of '12'. And I cannot find the right way to do it.
There are a lot of advices to use dynamics sql and construct full query string with required parameter values and then exec it, but if I will do it - the SSIS couldnt get columns data from the dynamics query.
Are there ways to solve it? Any ideas will be helpfull.
Thank you.
With regards, Yuriy.
回答1:
Create a string variable, say, SQL_Query. In variable definition - set EvaluateAsExpression and define expression as "your SQL statement ... @SESSION_ID = " + [User::Session_ID_Variable] + " rest of SQL statement"
where Session_ID_Variable contains your conditional value. If Session_ID_Variable is not string - you have to cast it to string with (DT_WSTR, length)
. Result in SQL_Query will be your target SQL expression.
Then in OLE DB Source - specify variable as SQL command source and select [User::SQL_Query].
Stored procedure have to return resultset of the same format in all cases. SP returning no resultset will fail DataSource.
来源:https://stackoverflow.com/questions/37725084/ssis-ole-db-source-as-stored-procedure-from-linked-server-with-parameters