select concat(p.pname, p.fname, " ",p.lname) as ptname, v.vstdate as "วันที่",v.hn ,s.name as "เพศ",v.age_y as "เพศ",oc.name as "อายุ",p.cid as "อาชีพ",v.pttype as
"เลขที่บัตรประชาชน"
,py.name as "สิทธิการรักษา",p.addrpart as "บ้านเลขที่",p.moopart as "หมู่ที่",t3.name as "ตำบล",t2.name as "อำเภอ",t1.name as "จังหวัด"
,sp.name as "แผนกที่รักษา",oi.name as "ประเภทการมา",v.pdx as "โรค",i.name as
"ชื่อโรค",v.income as "ค่าใช้จ่าย"
from vn_stat v
left outer join patient p on v.hn=p.hn
left outer join sex s on v.sex=s.code
left outer join occupation oc on p.occupation=oc.occupation
left outer join pttype py on v.pttype=py.pttype
left outer join thaiaddress t1 on t1.chwpart=p.chwpart and
t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=p.chwpart and
t2.amppart=p.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=p.chwpart and
t3.amppart=p.amppart and t3.tmbpart=p.tmbpart
left outer join ovst o on v.vn=o.vn
left outer join ovstist oi on o.ovstist=oi.ovstist
left outer join spclty sp on o.spclty=sp.spclty
left outer join icd101 i on v.pdx=i.code
where v.vstdate between "2010-09-01" and "2010-09-01" and v.pdx between "C00" and "C97"