insert into temp table select code example

Example 1: create and insert into temp table

IF(@Debug = 1)
    BEGIN

        --TempTables for Testing
        CREATE TABLE #_TempTable
        (
        FIRST       INT, 
         SECOND  INT,          
        );
        INSERT INTO  #_TempTable
               SELECT @FIRST, 
			          @SECOND
					  SELECT * FROM #_TempTable
	END;

Example 2: tsql create temp table

CREATE TABLE #haro_products (
    product_name VARCHAR(MAX),
    list_price DEC(10,2)
);

Example 3: select into temp table

SELECT t.col1, t.col2...
INTO #temp
FROM table1 AS t

Example 4: select into temp table

SELECT * 
INTO #temp
FROM (
    SELECT col1, col2
    FROM table1
) AS x

Tags:

Sql Example