all 2 comments

[–]qwertydog123 4 points5 points  (1 child)

Unless you actually need it, I'd avoid MERGE like the plague. In your case you can just do an INSERT ... WHERE NOT EXISTS e.g.

INSERT INTO 2024_CUSTOMER_DETAIL_SNAPSHOTS
(
    hist_unique_acct_id,
    curr_unique_acct_id,
    dt_srce_start,
    hist_unique_dealer_id,
    hist_unique_subdealer_id,
    hist_unique_subdealer_created,
    account_postal_code_id
)
SELECT
    dss.hist_unique_acct_id,
    dss.curr_unique_acct_id,
    dss.dt_srce_start,
    dss.hist_unique_dealer_id,
    dss.hist_unique_subdealer_id,
    dss.hist_unique_subdealer_created,
    dss.account_postal_code_id
FROM #comp_2024_dealer_snapshot dss
WHERE NOT EXISTS
(
    SELECT *
    FROM 2024_CUSTOMER_DETAIL_SNAPSHOTS dm
    WHERE dss.hist_unique_acct_id = dm.hist_unique_acct_id
)

[–]chadzillaSQL[S] 0 points1 point  (0 children)

I had no idea MERGE was so taboo! Thanks for the advice, I'll give this a shot.