select   e.id as  'Ա',E.EmpName as '',case sex when 'm' then '' when 'f' then 'Ů' end  as 'Ա', borndate as '',
  case marriage when 'n' then 'δ' when 'y' then 'ѻ' when 'o' then '' end as '',hireDate as 'ְ',
 departmentName as '',Duty as 'ְ',jobID as '',hireType as 'Ա',bankname as 'ͨ', Huji as 'ڵ',phone as '绰',fireDate as 'ְ',
 offType as 'ְԭ',c.pic as 'Ƭ', CONVERT(varchar(100), bb.[Date] , 23)as '䶯ʱ'
 , E.departmentCode as 'ű', e.id
 from employee E
LEFT JOIN Department AS D ON E.departmentcode=d.departmentcode
LEFT JOIN (select   distinct id,[date] from EMP_HistoryRecord  ) as  bb on e.id=bb.id and bb.[date]=(select   max([date]) from EMP_HistoryRecord where id=e.id  )
LEFT JOIN emp_pic AS C ON E.ID=C.ID  where 'a'='a'
