ลองเอา Code ไปปรับดูว่าใช้ได้หรือเปล่านะครับ ไม่รู้รายละเอียดครับ
select ro.department,ro.vn,ro.refer_number,ro.hn,d.name
as doctor_name,ro.refer_date,o.vstdate,ro.refer_time,o.vsttime,concat(p.pname,p.fname,' ',p.lname)
as ptname, concat(h.hosptype,' ',h.name) as hospname,pe.name as pttype_name, r.name
as refername, ro.refer_point,ro.pre_diagnosis,ro.pdx as icd,ic.name as icd_name,o.vstdate
from referout ro left outer join ovst o on o.vn = ro.vn
left outer join patient p on p.hn=ro.hn
left outer join hospcode h on h.hospcode = ro.hospcode
left outer join rfrcs r on r.rfrcs = ro.rfrcs
left outer join doctor d on d.code = ro.doctor
left outer join pttype pe on pe.pttype = o.pttype
left outer join icd101 ic on ic.code = ro.pdx
where ro.department = 'IPD'and ro.refer_date between '2011-01-01' and '2011-01-02'
union select ro.department,ro.vn,ro.refer_number,ro.hn,d.name as doctor_name,ro.refer_date,o.regdate as vstdate,ro.refer_time,o.regtime as vsttime,concat(p.pname,p.fname,' ',p.lname) as ptname, concat(h.hosptype,' ',h.name) as hospname,pe.name as pttype_name, r.name as refername,ro.refer_point,ro.pre_diagnosis,ro.pdx as icd,ic.name as icd_name,o.regdate as vstdate from referout ro left outer join ipt o on o.an = ro.vn left outer join patient p on p.hn=ro.hn left outer join hospcode h on h.hospcode = ro.hospcode left outer join rfrcs r on r.rfrcs = ro.rfrcs left outer join doctor d on d.code = ro.doctor left outer join pttype pe on pe.pttype = o.pttype left outer join icd101 ic on ic.code = ro.pdx where ro.department = 'IPD' and ro.refer_date between '2011-01-01' and '2011-01-02'
order by pttype_name