ลองเปลี่ยนตารางหลัก ก็ไม่ได้ครับ
GetDateRangeDialog(d1, d2);
ds1:= FormatDateTime('YYYY-MM-DD', d1);
ds2:= FormatDateTime('YYYY-MM-DD', d2);
c_name:= GetMultipleList('select s.name from spclty s ,ovst o ,opitemrece op '
+'where o.spclty=s.spclty and o.vn=op.vn '
+'and o.vstdate between "'+ds1+'" and "'+ds2+'" '
+'group by s.name ');
ShowMessage(c_name);
ChangeReportSQL('select o.vn ,o.hn ,o.an ,p.pname ,p.fname ,p.lname ,o.vstdate ,o.vsttime , '
+'o.spclty ,s.name as spclty_name , v.pdx , ic.name as pdx_name , ic.tname , '
+'o.pttype ,pt.name as ptt_name ,sum(op.sum_price) as price '
+'from ovst o '
+'left outer join patient p on p.hn = o.hn '
+'left outer join pttype pt on pt.pttype = o.pttype '
+'left outer join spclty s on s.spclty = o.spclty '
+'left outer join opitemrece op on op.vn = o.vn '
+'left outer join vn_stat v on v.vn = o.vn '
+'left outer join icd101 ic on ic.code = v.pdx '
+'where o.vstdate between "'+ds1+'" and "'+ds2+'" '
+'and o.an is null '
{+'and o.spclty = "01" ' }
+'and o.spclty = "'+c_name+'" '
+'group by o.vn ' );