คำสั่งก็ประมาณนี้ครับ
Var
a := String;
a := GetSQLStringData('select oapp_id from oapp where nextdate="'+FormatDateTime('yyyy-mm-dd',DBPipeline['nextdate'])+'" '+
' and clinic="'+DBPipeline['clinic']+'" '+
' order by oapp_id limit 1 ');
Value := GetSQLStringData('select count(oapp_id) as cc from oapp where '+
' nextdate="'+FormatDateTime('yyyy-mm-dd',DBPipeline['nextdate'])+'" '+
' and clinic="'+DBPipeline['clinic']+'" and oapp_id between "'+a+'" and "'+DBPipeline['oapp_id']+'" '+
' order by oapp_id ');