[color=red]ลองเพิ่มตามสีเขียวดูครับ[/color]
select ov.*,substring(concat(oost.name,' [',sp.department,']'),1,150) as ovstname, odx.icd10 as icdcode, vk.vn as lock_vn,pt.birthtime, substring(icd1.name,1,100) as icdname, concat(odx.icd10,' ',ix.name) as pdxname ,pt.birthday, pty.pcode, st.name as ovstist_name, concat(pt.pname,' ',pt.fname,' ',pt.lname) as ptname, oapp.nextdate as ndate,vt.age_y,vt.age_m,vt.age_d , vt.cid,c.complete,vt.pttype_in_region,vt.inc_drug,vt.count_in_day+1 as count_in_day , od.rw ,ovq.pttype_check,ovq.promote_visit,
rd.amount as "ยอดรวม",rd.paid as "จ่ายเอง"from ovst ov
left outer join patient pt on pt.hn=ov.hn
left outer join ovstdiag odx on odx.vn=ov.vn and odx.diagtype='1'
left outer join kskdepartment sp on sp.depcode=ov.cur_dep
left outer join ovstost oost on oost.ovstost=ov.ovstost
left outer join icd101 icd1 on icd1.code=odx.icd10
left outer join icd101 ix on ix.code=substring(odx.icd10,1,3)
left outer join pttype pty on pty.pttype=ov.pttype
left outer join vn_lock vk on vk.vn = ov.vn
left outer join ovstist st on st.ovstist = ov.ovstist
left outer join vn_stat vt on vt.vn=ov.vn
left outer join ovst_drgs od on od.vn = ov.vn
left outer join oapp on oapp.vn=ov.vn and oapp.app_no=1
left outer join vn_opd_complete c on c.vn=ov.vn
left outer join ovst_seq ovq on ovq.vn = ov.vn
left outer join rcpt_debt rd on vt.vn=rd.vn where ov.vstdate between'2014-08-05'and'2014-08-05'
order by ov.vsttime