qadirsyed


I have to transfer data from source to destination using stored procedures result set. There might be some more transformation needed to store the final result in the destination table.

Appreciate an early feedback.

Qadir Syed





Re: how to call a stored procedure in SSIS

Glenn Wellington


Just create a new instance of "OLE DB Command".

Pick and choose your connection, and call the command as exec <procedure name>






Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

"Oledb command" Source executes stored procedures.But it does not recognize the output of the stored procedure.
If I have a select statement at the end of the Stored procedure that returns me some columns,then those columns are not recognized by "OLEDB Command" as out put columns.



Is there any advice for executing such stored procedure





Re: how to call a stored procedure in SSIS

jaegd

Use a no-op select statement to "declare" metadata to the pipeline. Since stored procedures don't publish rowset meta-data like tables,views and table-valued functions, the first select statement of a stored procedure is used by the SQLClient OLEDB provider to determine column metadata.

Code Snippet

CREATE PROCEDURE dbo.GenMetadata
AS
SET NOCOUNT ON

IF 1 = 0
BEGIN
SELECT CAST(1 as smallint) as Fake
-- Publish metadata
END

-- do real work starting here
DECLARE @x char(1)
SET @x = (SELECT '1')


SELECT cast(@x as smallint)

RETURN











Re: how to call a stored procedure in SSIS

LittleBull

jaegd - thanks!!!



Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

It does not work If there are more than one rows are coming out of stored procedure.







Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

I got it solved on my end by replacing all temporary tables by temporary variables.





Re: how to call a stored procedure in SSIS

jaegd

Please give an example of what doesn't work for you.





Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

In the above post it should be table variable not temporary variable.

Conclusion:
It was table variable that Used instead of temporary table.





Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

Hey try with the example below

CREATE PROCEDURE dbo.GenMetadata
AS
SET NOCOUNT ON
CREATE TABLE #test(
[id] [int] NULL,
[Name] [nchar](10) NULL,
[SirName] [nchar](10) NULL
) ON [PRIMARY]


INSERT INTO #test
SELECT '1','A','Z' union all select '2','b','y'

select id,name,SirName
from #test
drop table #test
RETURN

Please let me know the result.




Re: how to call a stored procedure in SSIS

jaegd

With a local temp table created in the stored procedure, use a no-op select statement to "declare" metadata to the pipeline.

Code Snippet

IF OBJECT_ID('[dbo].[GenMetadata]', 'P') IS NOT NULL

DROP PROCEDURE [dbo].[GenMetadata]

GO

CREATE PROCEDURE [dbo].[GenMetadata]

AS

SET NOCOUNT ON

IF 1 = 0

BEGIN

-- Publish metadata

SELECT CAST(NULL AS INT) AS id,

CAST(NULL AS NCHAR(10)) AS [Name],

CAST(NULL AS NCHAR(10)) AS SirName

END

-- Do real work starting here

CREATE TABLE #test

(

[id] [int] NULL,

[Name] [nchar](10) NULL,

[SirName] [nchar](10) NULL

)

INSERT INTO #test

SELECT '1',

'A',

'Z'

UNION ALL

SELECT '2',

'b',

'y'

SELECT id,

[Name],

SirName

FROM #test

DROP TABLE #test

RETURN

GO





Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

Hi Thank you very much..

It is now working fine for the changes you suggested..




Re: how to call a stored procedure in SSIS

Mallikarjun n Channappagoudra

Hello,

With the procedure you have told,SSIS package able to detect output of the stored procedure.
But there another problem introduced bcz of this procedure.Where According to your procedure the SP returns two datasets.
First dataset having 1 row and this is as a result of First select statement.
Second dataset bcz of our actual select query.

So SSIS chooses first dataset,So returns only one row having Null values for all columns.

How to overcome from this




Re: how to call a stored procedure in SSIS

jaegd

Post a sproc, or usage of the above sproc, which demonstrates the problem (e.g. OPENQUERY, EXEC, INSERT EXEC, so on...)





Re: how to call a stored procedure in SSIS

ajedi2k

what if you want to execute a dynamic script i.e.

Code Block

create procedure etl.executeScript @scriptId int, @sessionId varchar(50)
as
set nocount on
declare @script nvarchar(max)

select @script=replace(script,'SESSION-ID',@sessionId)
from etl.script
where id=@scriptId

exec sp_executesql @script
return



exec etl.executeScript 1, 'my session'

basically every script has an id, and a sessionid. ole db command can't pick the meta data coming out of this stored procedure.

in the etl.script table, usually scripts meta data don't change, mostly it's the where class that changes.

when executing the ssis package, script id remains the same, the only thing that change is the sessionid. so for the engine meta data never changes, only the body does. for example a tipical script would look like

select fundid, fundname, descrptin
from dbo.currentsession
where sessionid='SESSION-ID'

so the etl.executeScript stroed procedure replace the sessionid with the passesed sessionid.

any help as to how i can get ole db source to show up the meta data in the columns section.

cheers