Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

Call StoredProcedure in SSIS

SQL 2008 - SSIS

How to invoke a Stored Procedure inside the SSIS Package ?

I am getting an error, when i wrote the exec storedprocedure in the SSIS Package.
- Executing (Warning)
	Messages
	* Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL Server Import and Export Wizard)
	
	* Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL Server Import and Export Wizard)

Open in new window

Avatar of lcohan
lcohan
Flag of Canada image

You can add a query task and call it like

EXEC stored_procedure par1,par2,....
Avatar of chokka

ASKER

This is written in Stored Procedure
declare @TempTable table  
(   
 NDC nvarchar(1000),   
 Qty nvarchar(1000)   
)  
  
Insert Into @TempTable (NDC,Qty)  
select    
     
   TR.NDC,     
   Sum(TR.[Dispensed Qty]) as Qty  
from  TransactionReport TR      
Group By    TR.NDC  
  
Insert Into @TempTable (NDC,Qty)  
select BR.NDC,BR.Qty  from BalanceReport BR  
  
  
select 
CAST(NDC AS VARCHAR) as NDC ,Sum(CONVERT(INT, Qty)) as Qty from  @TempTable  
Group By NDC

Open in new window

Ok not sure about its name but the command to call it in a Query task would be:

EXEC stored_proc_name;

one aspect though because you have temp table inside the SP...check your connection string (Manager) and make sure you run the SSIS task on a connection that is on the same server and temp table must go in temp db on the server where SSIS is running. If you need to do it on remote SQL servers use a DECLARE TABLE @temptable instead. A variable table does not care where you run it as it is not directly tied into tempdb database but if the data set in temp table is huge you may have performance issues.

Hope this helps.
In SSIS NVARCHAR is of type DT-WSTR and VARCHAR is of type DT-STR. So ensure proper casting before you pass the value.

Either you can perform datatype conversion in SSIS or SQL Procedure.
ASKER CERTIFIED SOLUTION
Avatar of chokka
chokka
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

Thats the solution for my issue