Same query as Check condition in sql server, just add this line to select section:
,isnull(a2.deptname,a1.deptname) as deptname
Same query as Check condition in sql server, just add this line to select section:
,isnull(a2.deptname,a1.deptname) as deptname