{"id":247,"date":"2012-12-18T15:37:09","date_gmt":"2012-12-18T15:37:09","guid":{"rendered":"http:\/\/www.sqlfreelancer.com\/blog\/?p=247"},"modified":"2014-03-06T15:48:33","modified_gmt":"2014-03-06T15:48:33","slug":"how-to-create-and-use-temp-tables-in-ssis","status":"publish","type":"post","link":"https:\/\/www.sqlfreelancer.com\/blog\/how-to-create-and-use-temp-tables-in-ssis\/","title":{"rendered":"How to create and use Temp tables in SSIS"},"content":{"rendered":"<p>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&#8217;ll walk through creating a simple temp table in SSIS.<\/p>\n<h3>Creating Sample SSIS Package<\/h3>\n<p>First, I will drag an Execute SQL Task into my Design view and rename it Create Temp Table:<\/p>\n<p><a href=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-249\" alt=\"SQL Freelancer SQL Server SSIS Temp Tables\" src=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables.png\" width=\"219\" height=\"78\" \/><\/a><br \/>\nNext, I will right click and edit and choose my connection and SQLStatement:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-250\" title=\"(The SQL statement used in this example is below)\" alt=\"SQL Freelancer SQL Server SSIS Temp Tables\" src=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-1.png\" width=\"624\" height=\"375\" srcset=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-1.png 624w, https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-1-300x180.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<div>\n<pre>IF OBJECT_ID('tempdb..##tmpTeams') IS NOT NULL\r\n    DROP TABLE ##tmpTeams\r\n    CREATE TABLE ##tmpTeams\r\n    (\r\n        Team VARCHAR(255),\r\n        Mascot VARCHAR(255),\r\n  State VARCHAR (2)\r\n    )\r\n    INSERT INTO ##tmpTeams VALUES\r\n       ('Auburn', 'Tigers', 'AL'),\r\n       ('Alabama', 'Crimson Tide', 'AL'),\r\n       ('Mississippi', 'Rebels', 'MS'),\r\n       ('Louisiana State', 'Tigers', 'LA'),\r\n       ('Mississippi State', 'Bulldogs', 'MS'),\r\n ('Arkansas', 'Razorbacks', 'AR'),\r\n ('Texas A&amp;M', 'Aggies', 'TX'),\r\n ('Georgia', 'Bulldogs', 'GA'),\r\n ('Tennessee', 'Volunteers', 'TN'),\r\n ('Vanderbilt', 'Commodores', 'TN'),\r\n ('Florida', 'Gators', 'FL'),\r\n ('South Carolina', 'Gamecocks', 'SC'),\r\n ('Missouri', 'Tigers', 'MO')<\/pre>\n<\/div>\n<p>Next, I will drag a Data Flow task into my Design view, rename it Query and drag the precedence constraint between the two:<\/p>\n<p><a href=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-251\" alt=\"SQL Freelancer SQL Server SSIS Temp Tables\" src=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-2.png\" width=\"219\" height=\"175\" \/><\/a><br \/>\nFor 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.<\/p>\n<p><a href=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-252\" alt=\"SQL Freelancer SQL Server SSIS Temp Tables\" src=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-3.png\" width=\"208\" height=\"172\" \/><\/a><\/p>\n<p>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:<\/p>\n<div>\n<pre>CREATE TABLE ##tmpTeams\r\n    (\r\n        Team VARCHAR(255),\r\n        Mascot VARCHAR(255),\r\n  State VARCHAR (2)\r\n    )<\/pre>\n<\/div>\n<p>Once the table has been created, let&#8217;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:<\/p>\n<p><a href=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-253\" alt=\"SQL Freelancer SQL Server SSIS Temp Tables\" src=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-4.png\" width=\"624\" height=\"347\" srcset=\"https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-4.png 624w, https:\/\/www.sqlfreelancer.com\/blog\/wp-content\/uploads\/2014\/03\/SQL-Server-SSIS-Temp-Tables-4-300x166.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.mssqltips.com\/sqlservertip\/2826\/how-to-create-and-use-temp-tables-in-ssis\/\" target=\"_blank\">Click here to view the rest of this post.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[59,60,50,58],"class_list":["post-247","post","type-post","status-publish","format-standard","hentry","category-integration-services-ssis","tag-development","tag-sql-server-integration-services","tag-ssis","tag-temp-tables"],"_links":{"self":[{"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/comments?post=247"}],"version-history":[{"count":2,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlfreelancer.com\/blog\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}