tags:

views:

200

answers:

3

In one SQL Task can I create a table variable

DELCARE @TableVar TABLE (...)

Then in another SQL Task or DataSource destination and select or insert into the table variable?

The other option I have considered is using a Temp Table.

CREATE TABLE #TempTable (...)

I would prefer to use Table Variable so that it remains in memory. But can use temp table if it is not possible to use table variable. Also I cannot use the record set destination as I need to preform straight SQL tasks on it later on.

The use case that this is trying to solve is essentially performing a transformation in the stead of BizTalk. There is a very large flat file to flat file transformation that BizTalk has to transform unfortunately the data volume would produce unacceptable load on the BizTalk server so the idea is to off load it to SSIS. However, it is not a simple row to row transformation, there are different types of rows which have relations to each other. The first task in SSIS is to load the row into appropriate (temp) tables, then in the second data task a select is preformed with the correct format for output.

A: 

The SSIS package would be run in a job. I assume it runs inside a SQL job. In that case, using a temp table won't harm. SQL Jobs are generally run after office hours so it does not matter.

Yogendra
I am afraid that more than one instances of this SSIS package could be run at once.
aceinthehole
And each instance would have its own #temp table.
HLGEM
You are correct. I have found that retain same connections for my purposes is causing significant performance issues. I am having to use Global Temp tables ##.
aceinthehole
+1  A: 

You could use some of the techniques in this post: http://consultingblogs.emc.com/jamiethomson/archive/2006/11/19/SSIS_3A00_-Using-temporary-tables.aspx
especially the ones about using RetainSameConnection=TRUE on the connection manager.
I would be interested to see more information about what use case you have that requires you to write out data to a temp table or table variable before further SSIS processing. Couldn't you take care of all of the SQL required steps in your source query before you start processing the dataflow with SSIS?

William Todd Salzman
Or with Execute SQL Tasks after? If multiple packages/instances can run the same process concurrently, temp tables would be fine. But to close the door on the original question - NO - you can NOT use table variables in SSIS.
Todd McDermid
Thanks Todd, Honestly I hadn't tried, I just assumed that if you could, it would need to follow the same workarounds that temp tables need. I was trying to point @aceinthehole towards defining the question better so that we could help solve the actual problem rather than use the temp table workarounds.
William Todd Salzman
A: 

Table variables are not kept solely in memory and can be written to disk under memory pressure. I tend to use table variables for very small lookups. If you Need to push a table into SQL Server due to necessary and complex transformations, then use a 'permanent' temp table that is truncated within the SSIS package prior to insert. Simple and will get what you need done.

Josef Richberg