John Woo が提案したものとは別に、さらに 2 つのオプションがあります。
左結合の使用
INSERT INTO tbl_Snapshot
SELECT *
FROM @mtts mtts
LEFT JOIN tbl_Snapshot ss ON mtts.MM = ss.MM AND mtts.ProjectID = ss.ProjectID
WHERE ss.MM IS NULL AND ss.tbl_Snapshot IS NULL
Merge ステートメントの使用 (Sql Server 2008 以降で機能します)
MERGE tbl_Snapshot AS ss
USING (SELECT * FROM @mtts) AS mtts
ON mtts.MM = ss.MM AND mtts.ProjectID = ss.ProjectID
WHEN NOT MATCHED THEN
INSERT([MM],[YYYY],[month_Start],[month_Finish],[ProjectID],[ProjectedBillable],[ProjectedPayable],
[ActualBilled],[ActualPaid],[Total_To_Bill],[Total_To_Pay])
VALUES(mm.[MM],mm.[YYYY],mm.[month_Start],mm.[month_Finish],mm.[ProjectID],mm.[ProjectedBillable],mm.[ProjectedPayable],
mm.[ActualBilled],mm.[ActualPaid],mm.[Total_To_Bill],mm.[Total_To_Pay]);
これは非常に汚い方法です (VARCHAR への CAST、次に MERGE、最後に COMPARE)。
INSERT INTO tbl_Snapshot
SELECT *
FROM @mtts mtts
WHERE CAST(mtts.MM AS vARCHAR(10)) + CAST(mtts.ProjectID AS VARCHAR(10))
NOT IN (SELECT CAST(ss.MM AS vARCHAR(10)) + CAST(ss.ProjectID AS VARCHAR(10)) FROM tbl_Snapshot ss)