$PBExportHeader$f_rpt_cksql.srf $PBExportComments$分解SQL语句--函数 global type f_rpt_cksql from function_object end type forward prototypes global subroutine f_rpt_cksql (string fsql, ref string ffield, ref string ffrom, ref string fwhere, ref string fgroup, ref string fsort) end prototypes global subroutine f_rpt_cksql (string fsql, ref string ffield, ref string ffrom, ref string fwhere, ref string fgroup, ref string fsort);string ls_sql//select ... from ... where ... group by ... order by ... int l[6] fsql=trim(fsql) ls_sql=lower(fsql) ls_sql=f_replace(ls_sql,'~n',' ') l[1]=pos(ls_sql,' from ') l[2]=pos(ls_sql,' where ') l[3]=pos(ls_sql,' group by ') l[4]=pos(ls_sql,' order by ') l[5]=len(ls_sql) ffield=trim(mid(fsql,8,l[1] -8)) l[6]=l[5]+1 if l[2]>0 then l[6]=min(l[6],l[2]) if l[3]>0 then l[6]=min(l[6],l[3]) if l[4]>0 then l[6]=min(l[6],l[4]) ffrom=trim(mid(fsql,l[1]+6,l[6] -(l[1]+6))) if l[2]>0 then l[6]=l[5]+1 if l[3]>0 then l[6]=min(l[6],l[3]) if l[4]>0 then l[6]=min(l[6],l[4]) fwhere=trim(mid(fsql,l[2]+7,l[6] -(l[2]+7))) else fwhere='' end if if l[3]>0 then l[6]=l[5]+1 if l[4]>0 then l[6]=min(l[6],l[4]) fgroup=trim(mid(fsql,l[3]+10,l[6] -(l[3]+10))) else fgroup='' end if if l[4]>0 then l[6]=l[5]+1 fsort=trim(mid(fsql,l[4]+10,l[6] -(l[4]+10))) else fsort='' end if end subroutine