当前位置: 代码迷 >> PB >> 为什么在pb 中 sql语句后加了group by 就查询出错呢?解决思路
  详细解决方案

为什么在pb 中 sql语句后加了group by 就查询出错呢?解决思路

热度:151   发布时间:2016-04-29 09:22:42.0
为什么在pb 中 sql语句后加了group by 就查询出错呢?
1、
select distinct(fc_fcqk.fhqdh),clyf,yfyf,zcfy,hxren,hxrq,hxbz,hxother,kouk,bcfk,jydxx.hdfk,jydxx.dshk,fc_fhxx.other,fc_fhxx.chengyunshang,0 as xz,jsyxm,fhy,gsjbr,cksj 
from fc_fhxx,fc_fcqk,jydxx 
where fc_fcqk.fhqdh = fc_fhxx.fhqdh and jydxx.jydbh = fc_fhxx.jydbh 2、
select distinct(fc_fhxx.fhqdh),fc_fhxx.clbh,fc_fhxx.chengyunshang,clyf,zcfy,yfyf,cksj,jsyxm,gsjbr,kouk,hxren,hxrq,hxother,hxbz,sum(zzf) as zzf,sum(qitafy) as qitafy,sum(dshk) as dshk,sum(hdfk) as hdfk
from jydxx,fc_fhxx,fc_fcqk 
where jydxx.jydbh = fc_fhxx.jydbh and fc_fhxx.fhqdh=fc_fcqk.fhqdh
group by fc_fhxx.fhqdh,fc_fhxx.clbh,fc_fhxx.chengyunshang,clyf,zcfy,yfyf,jsyxm,gsjbr,cksj,kouk,hxrq,hxrq,hxother,hxbz,hxren

 如果用第一个查询语句 加上以下语句
string ls_cyxm

ls_cyxm = sle_cys.text
if ls_cyxm <> '' then
is_newselect = is_newselect + " and fc_fhxx.chengyunshang like '" + ls_cyxm + "%'"
end if可以 查询出来

但是如果用第二个就不行 了 提示datatwindow error 在关键字and 处 出错

但是我又必须用group by 语句 咋办


------解决方案--------------------
给楼主一下函数供参考

global type f_addwhere from function_object
end type

forward prototypes
global function integer f_addwhere (datawindow f_dw, string f_where)
end prototypes

global function integer f_addwhere (datawindow f_dw, string f_where);string ls_old,ls_new,ls_old1,ls_old2
int li_pos,li_pos2
f_where='('+f_where+')'
ls_old=trim(f_dw.describe("DataWindow.Table.Select"))
li_pos=pos(lower(ls_old),' order by')
li_pos2=pos(lower(ls_old),' group by')
if li_pos2>0 then li_pos=min(li_pos,li_pos2)
if li_pos>0 then
ls_old1=left(ls_old,li_pos -1)
ls_old2=mid(ls_old,li_pos)
else
ls_old1=ls_old
end if
li_pos=pos(lower(ls_old1),' where ')
if li_pos>0 then
ls_old1=left(ls_old1,li_pos -1)+' where ('+right(ls_old1,len(ls_old1) - li_pos -6)
ls_new=ls_old1+") and "+f_where+ls_old2
else
ls_new=ls_old1+" where "+f_where+ls_old2
end if
if f_dw.Modify('DataWindow.Table.Select="'+ls_new+'"')>'' then
return 0
else
return 1
end if

end function
  相关解决方案