[Solved] Rewrite query for SQL Server from Oracle


The FROM clause in the NOT EXISTS subquery is using the source table instead of the target table. Change the table name in the NOT EXISTS subquery to the target table name:

INSERT INTO swi (co, na, ci, ac, id, version, add) 
    SELECT co, na, ci, acc, id, ?, address 
    FROM swi_tmp 
    WHERE NOT EXISTS (SELECT 1 
                      FROM swi
                      WHERE
                          swi_tmp.co = swi.co
                          AND swi_tmp.na = swi.na
                     );

4

solved Rewrite query for SQL Server from Oracle