subCompanySql="select t.id, t.subcompanyname, t.supsubcomid, ( select distinct 1 as hasnext from hrmsubcompany_back s where (s.supsubcomid = t.id and (s.CANCELED IS NULL OR s.CANCELED != '1') and s.sync_date = '"+syncDate+"') ) as hassubnext, ( select distinct 1 as hasnext from HrmDepartment_back d where (d.subcompanyid1 = t.id and (d.CANCELED IS NULL OR d.CANCELED != '1') and d.sync_date = '"+syncDate+"')) as hasdeptnext, t.tlevel from hrmsubcompany_back t where (t.canceled IS NULL OR t.canceled != '1') and t.id != t.supsubcomid and tlevel <= 10000 and sync_date = '"+syncDate+"' order by t.supsubcomid, t.showorder, t.subcompanyname";
departmentSql="select t.id, t.departmentname, t.subcompanyid1, isnull(t.supdepid,0) as supdepid, (case when t.supdepid != 0 and ( select COUNT(id) from hrmdepartment_back where id = t.supdepid and sync_date = '"+syncDate+"')= 0 then 0 else 1 end) as isExist, ( select distinct 1 as hasnext from hrmdepartment_back d where d.supdepid = t.id and (CANCELED IS NULL OR CANCELED != '1') and sync_date = '"+syncDate+"') as hasnext, t.tlevel from hrmdepartment_back t where t.id != ISNULL(t.supdepid, 0) and tlevel <= 10000 and (t.canceled IS NULL OR t.canceled != '1') and (t.canceled IS NULL OR t.canceled != '1') and sync_date = '"+syncDate+"' order by t.subcompanyid1 asc , t.supdepid asc , t.showorder asc, t.departmentname asc";
}else{
subCompanySql="select t.id,t.subcompanyname,t.supsubcomid,(select distinct 1 as hasnext from hrmsubcompany s where (s.supsubcomid=t.id and (s.CANCELED IS NULL OR s.CANCELED !='1')) ) as hassubnext,(select distinct 1 as hasnext from HrmDepartment d where (d.subcompanyid1=t.id and (d.CANCELED IS NULL OR d.CANCELED !='1')) ) as hasdeptnext,t.tlevel from hrmsubcompany t where (t.canceled IS NULL OR t.canceled !='1') and t.id != t.supsubcomid and tlevel <= 10000 order by t.supsubcomid,t.showorder,t.subcompanyname";
departmentSql="select t.id,t.departmentname,t.subcompanyid1,isnull(t.supdepid,0) as supdepid,(case when t.supdepid != 0 and (select COUNT(id) from hrmdepartment where id = t.supdepid)=0 then 0 else 1 end) as isExist,(select distinct 1 as hasnext from hrmdepartment d where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')) as hasnext,t.tlevel from hrmdepartment t where t.id != ISNULL(t.supdepid,0) and tlevel <= 10000 and (t.canceled IS NULL OR t.canceled !='1') order by t.subcompanyid1 asc , t.supdepid asc , t.showorder asc, t.departmentname asc";