Inserting data into a temporary table

后端 未结 14 1377
情书的邮戳
情书的邮戳 2020-12-22 22:28

After having created a temporary table and declaring the data types like so;

CREATE TABLE #TempTable(
ID int,
Date datetime,
Name char(20))

H

相关标签:
14条回答
  • 2020-12-22 22:35
    insert #temptable
    select idfield, datefield, namefield from yourrealtable
    
    0 讨论(0)
  • 2020-12-22 22:39

    All the above mentioned answers will almost fullfill the purpose. However, You need to drop the temp table after all the operation on it. You can follow-

    INSERT INTO #TempTable (ID, Date, Name) SELECT id, date, name FROM physical_table;

    IF OBJECT_ID('tempdb.dbo.#TempTable') IS NOT NULL DROP TABLE #TempTable;

    0 讨论(0)
  • 2020-12-22 22:42
    INSERT INTO #TempTable (ID, Date, Name) 
    SELECT id, date, name 
    FROM physical_table
    
    0 讨论(0)
  • 2020-12-22 22:43

    The right query:

    drop table #tmp_table
    
    select new_acc_no, count(new_acc_no) as count1
    into #tmp_table
    from table
    where unit_id = '0007' 
    group by unit_id, new_acc_no
    having count(new_acc_no) > 1
    
    0 讨论(0)
  • 2020-12-22 22:46

    To insert all data from all columns, just use this:

    SELECT * INTO #TempTable
    FROM OriginalTable
    

    Don't forget to DROP the temporary table after you have finished with it and before you try creating it again:

    DROP TABLE #TempTable
    
    0 讨论(0)
  • 2020-12-22 22:46

    After you create the temp table you would just do a normal INSERT INTO () SELECT FROM

    INSERT INTO #TempTable (id, Date, Name)
    SELECT t.id, t.Date, t.Name
    FROM yourTable t
    
    0 讨论(0)
提交回复
热议问题