-- Case #1
-- Copying bulk data from Table1 to Table2
INSERT INTO Table2
SELECT * FROM Table1
WHERE ID NOT IN (SELECT ID FROM Table2)
-- AND (if any where conditions add here)
-- Case #2
-- Copying single row at a time
IF (SELECT COUNT(*) FROM Table2 WHERE ID = @ID) = 0
BEGIN
INSERT INTO Table2 SELECT * FROM Table1
-- WHERE ... (any where condition add here)
END
|