Using Temp tables in SSIS
NickName:Jason M Ask DateTime:2009-10-17T01:54:47

Using Temp tables in SSIS

I am using a Temporary table in Stored Procedure in SQL Server. I am trying to use that SP in OLE DB Source Editor.

I can see the data output returned in the Query Builder that comes with Build Query button. But when I Click the Columns tab, I am getting the below error.

- TITLE: Microsoft Visual Studio

Error at Data Flow Task [OLE DB Source [1]]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Invalid object name '##Payment'.".

Error at Data Flow Task [OLE DB Source [1]]: Unable to retrieve column information from the data source. Make sure your target table in the database is available.

Does that mean I cant use temp tables in SP, if I want it to be consumed by SSIS

Copyright Notice:Content Author:「Jason M」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1579476/using-temp-tables-in-ssis

Answers
Henrik Staun Poulsen 2011-02-22T10:10:24

UPDATE November 2020.\nThis post has been superceeded by How to EXEC a stored procedure from SSIS to get its output to text file\nthat describes how to run a stored procedure from SSIS\nexec mySproc WITH RESULT SETS ((i int))\n\nlook at the solution provided by Troy Witthoeft\nOld answer\nThere is another solution mentioned at https://web.archive.org/web/20120915093807/http://sqlserverpedia.com/blog/sql-server-bloggers/ssis-stored-procedure-metadata. Look at option 3.\n(November 2020; updated link)\nQuote:\nAdd some meta-data and the "set nocount on" to the stored procedure with a "short circuited if clause" (if 1=0), and a bogus select statement at the top. I've tested with trying to leave the "set nocount on" out and it did not work.\nCREATE PROCEDURE [dbo] . [GenMetadata] AS \nSET NOCOUNT ON \nIF 1 = 0 \n BEGIN\n -- Publish metadata \n SELECT CAST (NULL AS INT ) AS id , \n CAST (NULL AS NCHAR ( 10 )) AS [Name] , \n CAST (NULL AS NCHAR ( 10 )) AS SirName \n END \n\n -- Do real work starting here \nCREATE TABLE #test \n ( \n [id] [int] NULL, \n [Name] [nchar] ( 10 ) NULL, \n [SirName] [nchar] ( 10 ) NULL \n ) \n",


Jason M 2009-10-16T19:54:00

I used\n\nSET FMTONLY OFF \nat the start of procedure, which will tell not to process rows to the client\nwhen it is not being executed \nas there is no temp table while parsing the SP, hence no column available while parsing.\n\nIt got me working finally :)",


Registered User 2009-10-16T23:41:50

If the error was raised while you are in BIDS, then ajdams solution will not work as it only applies to errors raised while running the package from the SQL Server Agent.\n\nThe primary problem is that SSIS is struggling to resolve the meta data. From its stand-point, the ## tables don't exist since it can't return the meta data for the object during the pre-execution phase. So you have to find a way to satisfy its requirement that the table already exists. There are a few solutions:\n\n\nDon't use temporary tables. Instead, create a working database and put all your objects in it. Obviously, this probably won't work if you are trying to get the data on a server where you aren't a dbo like a production server, so you can't rely on this solution.\nUse CTE's instead of temporary tables. This works if your source server is 2005/2008. This won't help if the source server is 2000.\nCreate the ## table in a separate Execute SQL command. Set the connection's RetainSameConnection property to True. Set DelayValidation to true for the data flow. When you setup the data flow, fake it out by temporarily adding a SELECT TOP 0 field = CAST(NULL AS INT) to the top of the stored procedure that has identical meta data to your final output. Remember to remove this from the stored procedure before you run the package. This is also a handy trick for sharing temporary table data between data flows. If you want the rest of the package to use separate connections so that they can run in parallel, then you have to create an additional non-shared connection. This evades the problem since the temporary table already exists at the time the data flow tasks runs.\n\n\nOption 3 achieves your goal, but it is complicated and has the limitation that you have to separate the create ## command into another stored procedure call. If you have the ability to create stored procedures on the source server, then you probably also have the ability to create other objects like staging tables and this is usually a better solution. It also side-steps possible TempDB contention issues which is a desirable benefit as well.\n\nGood luck and let me know if you need further guidance on how to implement step 3.",


ajdams 2009-10-16T18:06:58

Nope, it's a permissions issue. This should help you:\n\nhttp://support.microsoft.com/kb/933835",


AndyM 2010-02-17T14:45:56

For all the hassle involved, I think it is probably just not worth it. Create a real table in the db and truncate it before / after your load. If it's for a datawarehouse it isn't going to matter if you have an extra table or two. This gives you the design-time SSIS tools and means you don't have to worry about the intracacies of temp tables.\n\nIf you want to keep things separate, then just create your SSIS temp tables in a separate schema. You can use permissions to make this schmema invisible to all other users.\n\nCREATE SCHEMA [ssis_temp]\n\nCREATE TABLE [ssis_temp].[tempTableName]\n",


Irawan Soetomo 2015-10-09T19:19:13

These steps helped me:\n\n\nWrite the final result set into a table.\nScript that table as CREATE into a new New Query Editor Window.\nRemove everything except the open and close brackets that define the columns.\nWrap that into another pair of brackets.\nRecompose the calling of your SP from\n\nexec p_MySPWithTempTables ?, ?\n\n\ninto\n\nexec p_MySPWithTempTables ?, ? with result sets\n(\n (\n ColumnA int,\n ColumnB varchar(10),\n ColumnC datetime\n )\n)\n",


More about “Using Temp tables in SSIS” related questions

Using SSIS temp tables and use result set for the package?

Hi I am using complex SQL Server Query where i am joining temp tables and use within the package. How can I use this result set in SSIS? I can’t use Stored Procedure because I can’t get admin rig...

Show Detail

Using Temp tables in SSIS

I am using a Temporary table in Stored Procedure in SQL Server. I am trying to use that SP in OLE DB Source Editor. I can see the data output returned in the Query Builder that comes with Build Qu...

Show Detail

Use temp tables in SSIS packages

I am writing a basic file dump from one database to another. I am using SSIS 2008 and creating several packages to transform the data I have from a MSSQL 2010 database to a MYSQL 5.1 database. Al...

Show Detail

Using temporary tables in ssis package

i have a problem - I want to use temp table in stored procedure is SQL Server, which will be executed from SSIS package. I read some tips how to do it and I tried this one (first answer): Using Temp

Show Detail

Generating SSIS packages with BIML that use Stored Procedures with temp tables

As most of you know, SSIS has a hard time reading metadata whenever a stored procedure with temp tables is used as an OleDbSource. Previously, this could be easily prevented by adding SET FMTONLY O...

Show Detail

SSIS: recordset or temp table

I have an SSIS application that needs to get data from 2 databases of different servers (not link). I need to get the match names and DOB records between 2 database then use the results to insert/u...

Show Detail

SSIS running SQL Agent job with Creating temp table tasks

I'm developing packages using multiple exec sql tasks objects that create temp tables, used later on data flow tasks. Local executions of the package work, but I couldn't test this out in SQL Server.

Show Detail

Export temp table to excel in SSIS

Hi everyone I have small doubt in SSIS package: I am using a stored procedure which is giving set of records, finally these records will be saved in temp table. The thing is now I want this recor...

Show Detail

ssis temp table exec proc

SSIS newbie here. I have an SSIS package I created based on the wizard. I added a SQL task to run the script I was running previously separately, in order to reduce the process to one step. The ...

Show Detail

SQL SSIS Help. Import an excel sheet into a temp table

I have a farily simple task of taking an Excel sheet and importing it into a SQL 2005 database table. I need to create an SSIS task for this. The Excel sheet does not have all the columns I need to

Show Detail