1
การเขียน SQL Script / Re: ขอคำแนะนำสร้างรายงานรูปแบบรายงาน Multiplelist
« เมื่อ: มิถุนายน 17, 2016, 15:47:01 PM »
ใช้ได้แล้วครับผม
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 s.spclty=o.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 s.name in ('+c_name+') '
+'group by o.vn ' );
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 s.spclty=o.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 s.name in ('+c_name+') '
+'group by o.vn ' );