The easiest way is to add a if clause and check customerCode for not null. if its null, perform the query without the join, if its not null perform the query with the join.
customerCode