I found some similar questions but none exactly matching my use case.
When trying to use a MERGE statement Microsoft mentions the following:
Source
It’s important to specify only the columns from the target table to use for matching purposes. That is, specify columns from the target table that are compared to the corresponding column of the source table. Don’t attempt to improve query performance by filtering out rows in the target table in the ON clause; for example, such as specifying AND NOT target_table.column_x = value. Doing so can return unexpected and incorrect results.
In another place it mentions that you could use views to “filter” the source table.
Source
Define a view on the source or target that returns the filtered rows and reference the view as the source or target table. If the view is defined on the target table, any actions against it must satisfy the conditions for updating views. For more information about updating data by using a view, see Modifying Data Through a View.
But what I cannot find is whether or not you can “safely” use a subquery instead of the source table.
For example:
MERGE TableA a
USING (
SELECT *
FROM TableB b
WHERE
b.Status = 5
) b
ON a.ID = b.ForeignID
... MATCH statements ...
Would this cause similar problems as using a CTE or filtering by using the ON statement?