Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT AccountsAdded(AccountNum, Name) SELECT AccountNum, Name FROM AccountsNew WHERE AccountNumber not in (SELECT AccountNum FROM AccountsCurrent)
- INSERT AccountsRemoved(AccountNum, Name) SELECT AccountNum, Name FROM AccountsCurrent WHERE AccountNumber not in (SELECT AccountNum FROM AccountsNew)
- TRUNCATE TABLE AccountsCurrent
- INSERT AccountsCurrent(AccountNum, Name) SELECT AccountNum, Name FROM AccountsNew
- TRUNCATE TABLE AccountsNew
- INSERT INTO [table] (
- [fields]
- )
- SELECT
- [fields]
- FROM
- [table1]
- LEFT JOIN
- [table2]
- ON [join condition]
- WHERE
- [table2].[id] IS NULL
- INSERT INTO [table] (
- [fields]
- )
- SELECT
- [fields]
- FROM
- [table1]
- WHERE
- EXISTS (SELECT * FROM [table2] WHERE [condition to match tables 1 and 2])
- -- # This is quick provided that all fields to match the two tables are
- -- # indexed in both tables. Should then be much faster than the IN clause.
Add Comment
Please, Sign In to add comment