title: How to generate temp table columns and datatypes automatically via script
body: <p>I create temp tables quite often in SQL and I am looking into a way to generate the column names and datatypes automatically for the table definition so I don't have to look them all up everytime.</p>
  
  <p>For example I run:</p>
  
  <pre><code>SELECT CustomerID
    ClientID,
    FirstName
    LastName
  INTO #Test
  From dbo.Customer
  </code></pre>
  
  <p>To initially setup the temp table with the appropriate columns and data I need. Once I get that all done, I then go back in and take out the INTO statement and write the following:</p>
  
  <pre><code>CREATE TABLE #Test
  (
  ...
  ...
  );
  </code></pre>
  
  <p>I want to find a way to auto generate the column names and datatypes from the initial creation of the temp table. Right now, since I am initially inserting into an automatically created temp table, I use this:</p>
  
  <pre><code>EXEC tempdb..sp_help '#Test';
  </code></pre>
  
  <p>This gives me everything I need without having to look all the column datatypes up, but I wanted to know if there was a way to just auto gen the column names off of something like this. So the auto gen would generate:</p>
  
  <pre><code>CustomerID int,
  ClientID int,
  FirstName varchar(50),
  LastName varchar(50)
  </code></pre>
  
  <p>This would allow me to just copy and paste this into my create table statement.</p>