SELECT 'HOSPCODE','PID','SEQ','DATE_SERV','LABTEST','LABRESULT','D_UPDATE','LABPLACE','CID' union all
(SELECT v.pcucodeperson HOSPCODE,v.pid PID,888888 SEQ
,concat(substr(v.dateservice,1,4),'',substr(v.dateservice,6,2),'',substr(v.dateservice,9,2))  DATE_SERV
,'0621201' LABTEST,v.resulthct LABRESULT
,concat(substr(p.dateupdate,1,4),'',substr(p.dateupdate,6,2),'',substr(p.dateupdate,9,2)
,'',substr(p.dateupdate,12,2),'',substr(p.dateupdate,15,2),'',substr(p.dateupdate,18,2)) D_UPDATE
,'00000' LABPLACE
,p.idcard CID
FROM studenthealthhctthalas v
LEFT JOIN person p on v.pid =p.pid
WHERE v.resulthct is not null  
INTO OUTFILE 'C:/JHCIS_export/HCT/labfu.txt'
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\r\n');