Just replace merge with a subquery using IN and you don't need all this handcoded SQL.