select v.hn as HN,p.cardno as CID,o.icd10 as ICD10,pt.informname as N1,pt.informaddr as N2,
concat(pt.pname,pt.fname," ",pt.lname) as fullname,s.name as sex ,pt.birthday,
v.vstdate,na.name as nationality,pt.hometel
from vn_stat v,ovstdiag o,visit_pttype vp,ptcardno p,patient pt
left outer join sex s on s.code=pt.sex
left outer join nationality na on na.nationality=pt.nationality
where v.vn=o.vn and v.vn=vp.vn and v.hn = pt.hn and vp.pttype="52"
and o.icd10 in ("Z021","Z027") and p.hn=v.hn
and v.vstdate between "2008-02-11" and "2008-02-11" group by v.hn
เปลี่ยนที่ผม mark สีแดง ไว้เป็น
concat(left(p.cardno,1),mid(p.cardno,3,4),mid(p.cardno,8,5),mid(p.cardno,14,2),mid(p.cardno,17,1)) as CID น่าจะได้ครับ