Creating temp tables in SSIS seems like a straight-forward process using the Execute SQL Task, however there are a couple of properties that must be changed. In this post, we’ll walk through creating a simple temp table in SSIS.
Creating Sample SSIS Package
First, I will drag an Execute SQL Task into my Design view and rename it Create Temp Table:
IF OBJECT_ID('tempdb..##tmpTeams') IS NOT NULL DROP TABLE ##tmpTeams CREATE TABLE ##tmpTeams ( Team VARCHAR(255), Mascot VARCHAR(255), State VARCHAR (2) ) INSERT INTO ##tmpTeams VALUES ('Auburn', 'Tigers', 'AL'), ('Alabama', 'Crimson Tide', 'AL'), ('Mississippi', 'Rebels', 'MS'), ('Louisiana State', 'Tigers', 'LA'), ('Mississippi State', 'Bulldogs', 'MS'), ('Arkansas', 'Razorbacks', 'AR'), ('Texas A&M', 'Aggies', 'TX'), ('Georgia', 'Bulldogs', 'GA'), ('Tennessee', 'Volunteers', 'TN'), ('Vanderbilt', 'Commodores', 'TN'), ('Florida', 'Gators', 'FL'), ('South Carolina', 'Gamecocks', 'SC'), ('Missouri', 'Tigers', 'MO')
Next, I will drag a Data Flow task into my Design view, rename it Query and drag the precedence constraint between the two:
For the Data Flow task we are going to query the temp table and export the results to a database table. Right click the Data Flow task and choose Edit. Drag a OLE DB Source and a OLE DB Destination task into the Design view.
To avoid errors when configuring the OLE DB Source we need to create the temp table first using SSMS. In SSMS run the following statement to create a global temp table:
CREATE TABLE ##tmpTeams ( Team VARCHAR(255), Mascot VARCHAR(255), State VARCHAR (2) )
Once the table has been created, let’s go back into our SSIS package. Right click OLE DB Source and choose Edit. Choose your data source and choose SQL command for the Data access mode dropdown. In the SQL command text we will need to create our SQL statement: