BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: nu51313932nu ที่ เมษายน 10, 2017, 10:28:54 AM

หัวข้อ: ปิดกระทู้ครับผม
เริ่มหัวข้อโดย: nu51313932nu ที่ เมษายน 10, 2017, 10:28:54 AM
จากโค้ดนี้นะครับ  มี error คือมันบอกจำนวนคอลัมน์ไม่เท่ากัน   


คือต้องการให้
1.  1หน้ามียาสูงสุดแค่ 6 ตัว
2.   ถ้าหน้าสุดท้ายมีเศษ  คือไม่ครบ 6 ตัวให้ทำตารางเปล่าออกมาให้เต็ม

(https://www.mx7.com/i/120/xJiMfc.png)
โค๊ด: [Select]
procedure GlobalOnCreate;

begin
      GetDateRangeDialog(date1, date2);
      ds1 := FormatDatetime('yyyy-mm-dd',date1);
      ds2 := FormatDatetime('yyyy-mm-dd',date2);
      an := GetUserParameter(0);
      hn := GetSQLStringData('select hn from ipt where an = "'+an+'"');
      count_record := GetSQLIntegerData('select count(op.icode) from opitemrece op '+
                      ' left outer join drugitems di on di.icode = op.icode'+
                      ' left outer join sp_use sp on op.sp_use = sp.sp_use'+
                      ' where an="'+an+'" and op.rxdate between "'+ds1+'" and  "'+ds2+'"'+
                       ' and NOT(op.drugusage = "" '+
                       ' and op.sp_use  = "")');

      {showmessage(IntToStr(count_record));}

      sql := 'select concat(di.name,"  ",di.strength),op.drugusage, op.sp_use'+
                       ' from opitemrece op '+
                       ' left outer join drugitems di on di.icode = op.icode'+
                      ' left outer join sp_use sp on op.sp_use = sp.sp_use'+
                      ' where an="'+an+'" and op.rxdate between "'+ds1+'" and  "'+ds2+'"'+
                        ' and NOT(op.drugusage = "" '+
                       ' and op.sp_use  = "")';
                     
                     
while count_record >= 6 do
         begin
                count_record :=   count_record-6;
         end;

         if count_record<>0 then
            newline := 6-count_record;


         while newline > 0 do
         begin
           sql := sql + ' union select "","'+IntToStr(newline) +'"'  ;
           newline := newline - 1;
         end;


      {showmessage(sql);}
      ChangeReportSQL(sql);
end;