Search code examples
sqlsql-serversql-server-2008temp-tables

How to insert into a table from temp table?


I already have values in a temp table and I want to insert it into my table.

I follow this syntax

IF NOT EXISTS (SELECT 1 FROM ABC abc JOIN #Temp t ON abc.ID = t.ID)

insert into MyTable(Id,Name)
select values (t.ID, t.Name)
From t

I have just the name t as an alias I created in a condition before this insert.

Is this correct? Some people use @ etc. I am confused.


Solution

  • Correct syntax:

    insert into MyTable(Id,Name)
    select t.ID, t.Name
    From #temp t
    

    Always read manual