Tuesday, July 15, 2014

SSIS 2012 not working with temp tables

For my SSIS project  using stored procedures inside an OLEDB Source component

Initially, my stored procedure used in temp variable,  so when I run the package I am getting some performance issue,  then, I moved to temp table logic  to modify the stored procedure.
Then I tried to run the package I am getting the below error

“The metadata could not be determined because statement ‘<sql statement>’ in procedure ‘<procedure name>’ uses a temp table.”.

Solution
I followed some steps to achieve the SSIS metadata issue

Old Stage
Procedure my Procedure ()
AS
BEGIN
SET NoCount ON
SET FMTONLY OFF
CREATE #TempTable (Column1 int, ……)
SELECT …..
FROM #tempTable
Some Update/Insert/Delete in temp table
Then “SELECT Column1, Column2, Column3…
FROM #TempTable”

Modified Procedure
Procedure my Procedure ()
AS
BEGIN
SET NoCount ON
SET FMTONLY OFF
CREATE #TempTable (Column1 int, ……)
SELECT …..
FROM #tempTable
Some Update/Insert/Delete in temp table
Then “SELECT N_Column1 = column1, N_Column2 = Column2, N_ Column3 = Column3
FROM #TempTable”

Then updated SSIS package Source code

EXEC [dbo].[MyProcedure] WITH RESULT SETS ((N_Column1 int, N_Column2 varchar(20), NColumn3 varchar(20) ))

Now I can able to retrieve data from storedprocedure using temptable.