Export person 43 files structure
########################################
SELECT DISTINCT  trim(person.pcucodeperson) AS pcucode, 
person.idcard, 
person.pid, 
person.hcode,  
person.prename, 
person.fname, 
person.lname, 
person.sex, 
IF(person.birth IS NULL OR TRIM(person.birth)='' OR person.birth LIKE '0000-00-00%','',DATE_FORMAT(person.birth,'%Y%m%d')) AS birth,  
person.roadmoi, 
person.hnomoi, 
if(length(trim(person.mumoi))=1,concat('0',trim(person.mumoi)),
if(trim(person.mumoi)='' or mumoi is NULL,'00',mumoi)) as mumoi,  
person.subdistcodemoi, 
person.distcodemoi, 
person.provcodemoi,  
person.marystatus,  
IF(person.origin IS NULL OR TRIM(person.origin)='','',person.origin) AS origin,  
IF(person.nation IS NULL OR TRIM(person.nation)='','',person.nation) AS nation,person.religion,
IF(person.educate IS NULL OR person.educate NOT IN('00','01','02','03','04','05','06','09'),'09',
person.educate) educate , 
person.familyposition, 
person.fatherid, 
person.motherid, 
person.mateid,  
IF(person.datein IS NULL OR TRIM(person.datein)='' OR person.datein LIKE '0000-00-00%','',
DATE_FORMAT(person.datein,'%Y%m%d')) AS movein,  
person.dischargetype AS dischar,  
IF(person.dischargedate IS NULL OR TRIM(person.dischargedate)='' OR person.dischargedate LIKE '0000-00-00%','',
DATE_FORMAT(person.dischargedate,'%Y%m%d')) AS ddisch,  
concat(ifnull(bloodgroup,''),ifnull(bloodrh,'')) as bloodgroup , 
if(nation='94' or nation='95' or nation='99','',
if(intercode IN('01','02','03','11','12','13','14','15','16','17','18','21','22','23'),intercode,'23') ) as intercode,
 if(typelive='0','1',if(typelive='5','0',typelive)) as typelive,  
IF(house.villcode IS NOT NULL,house.villcode,'') AS villcode,  
IF(length(occupa) > 3,'',occupa) AS mapoccupation,  
IF(cnation.mapnation IS NOT NULL AND TRIM(cnation.mapnation)<>'',cnation.mapnation,'') AS mapnation,  
IF(cnationrace.mapnation IS NOT NULL AND TRIM(cnationrace.mapnation)<>'',cnationrace.mapnation,'') AS maporigin,  
IF( person.dateupdate IS NULL OR TRIM(person.dateupdate)='' OR person.dateupdate LIKE '0000-00-00%','',DATE_FORMAT(person.dateupdate,'%Y%m%d%H%i%s') ) AS d_update ,
if(length(trim(occupa)) < 4,'',occupa) occupa_new ,'' vstatus ,if(Ucase(bloodrh)='P','1',if(Ucase(bloodrh)='N','2','')) bloodrh ,ifnull(passpotnumber,'') passport  FROM person  LEFT JOIN house ON (person.pcucodeperson=house.pcucode AND person.hcode=house.hcode)  LEFT JOIN coccupa ON (person.occupa=coccupa.occupacode)  LEFT JOIN cnation ON (person.nation=cnation.nationcode)  LEFT JOIN cnation cnationrace ON (person.origin=cnationrace.nationcode)  LEFT JOIN persondeath pd ON person.pcucodeperson=pd.pcucodeperson AND person.pid=pd.pid  WHERE TRIM(person.pcucodeperson)<>'' AND person.pcucodeperson='03811' AND trim(person.fname) <> 'เบิกวัสดุ'  AND pd.pid IS NULL ORDER BY person.pcucodeperson ASC, person.pid ASC