在DBGridEh中间生成合计行(50分)

  • 主题发起人 jackson_wu
  • 开始时间
J

jackson_wu

Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现这样的效果:<br>porder &nbsp; code &nbsp;name &nbsp;klotvalue bunr &nbsp; bumo &nbsp; &nbsp;kvol &nbsp; ndate &nbsp; &nbsp;fdate &nbsp; &nbsp; jitu0<br>A001 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; AB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1200<br>A002 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; AB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060902 20060922 &nbsp;1500<br>合计 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2700<br>A009 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; CB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1200<br>A010 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; CB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1100<br>合计 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2300<br>我的SQL语句是这样写的:<br> &nbsp;with self.ADOQuery1 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Close;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.SQL.Clear;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.SQL.Add(<br> &nbsp; &nbsp; &nbsp;'select a.porder,a.code,c.name,f.klotvalue,e.bunr,a.bumo,d.kvol,left(d.ndate,8) ndate,left(a.fdate,8) fdate,a.jitu0 from tpics31.dbo.xsact a '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join (select porder,ocnt from sks.dbo.hs_proc where KBAN='+''''+'999'+''''+ ' and class='+''''+'j'+''''+') b on a.porder=b.porder '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join tpics31.dbo.xhead c on a.code=c.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join (select distinct code, bunr from tpics31.dbo.xitem) e on a.code=e.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join tpics31.dbo.xslip d on a.porder=d.porder and a.code=d.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join sks.dbo.hs_procl f on a.porder =f.kporder &nbsp;and f.klotcode='+''''+'9998'+''''<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' where a.porder in (select porder from sks.dbo.hs_proc where KBAN='+''''+'999'+''''+' and class='+''''+'j'+''''+')'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' and &nbsp;a.code like :strcode &nbsp;and &nbsp;e.bunr like :strbunr &nbsp;and &nbsp;a.bumo like :strbumo &nbsp;and &nbsp;a.fdate like :strfdate '<br><br> &nbsp; &nbsp; &nbsp; +' union ' &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' select porder='+''''+'合计'+''''+' ,code,name='+''''+''''+',klotvalue='+''''+''''+',bunr='+''''+''''+',bumo='+''''+''''<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' ,sum(kvol) kvol,ndate='+''''+''''+',fdate='+''''+''''+',sum(jitu0) jitu0 from ('<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' select a.porder,a.code,c.name,f.klotvalue,e.bunr,a.bumo,d.kvol,left(d.ndate,8) ndate,left(a.fdate,8) fdate,a.jitu0 from tpics31.dbo.xsact a '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join (select porder,ocnt from sks.dbo.hs_proc where KBAN='+''''+'999'+''''+ ' and class='+''''+'j'+''''+') b on a.porder=b.porder '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join tpics31.dbo.xhead c on a.code=c.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join (select distinct code, bunr from tpics31.dbo.xitem) e on a.code=e.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join tpics31.dbo.xslip d on a.porder=d.porder and a.code=d.code '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' left join sks.dbo.hs_procl f on a.porder =f.kporder &nbsp;and f.klotcode='+''''+'9998'+''''<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' where a.porder in (select porder from sks.dbo.hs_proc where KBAN='+''''+'999'+''''+' and class='+''''+'j'+''''+')'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' and &nbsp;a.code like :strcode &nbsp;and &nbsp;e.bunr like :strbunr &nbsp;and &nbsp;a.bumo like :strbumo &nbsp;and &nbsp;a.fdate like :strfdate ) a '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +' group by a.code '<br> &nbsp; &nbsp; &nbsp; +' order by a.code ' );<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strcode').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strcode').Value:=Trim(self.Edit1.Text)+'%';<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strbunr').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strbunr').Value:=Trim(self.ComboBox2.Text)+'%';<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strbumo').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strbumo').Value:=Trim(self.ComboBox1.Text)+'%';<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strfdate').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.Parameters.ParamByName('strfdate').Value:=self.Edit2.Text+'%';<br> &nbsp; &nbsp; &nbsp;self.ADOQuery1.open;<br>union下面是生成合计行,程序在执行时报错:不正常地定义参数对象,提供了不一致或不完整的信息,如果我把union上面或下面单独执行,不报错,请高手指点心一下。
 
参数名不要重复,即使值一样,比如前一个是:strfdate,后一个写为:strfdate1再赋值
 
dey-99 谢谢你的回答,我肯定给分。<br>另外我还想再问一下,对于这样的情况有没有比较简单的方法,如果告诉我我另外再给分
 
建议把这些语句写在存储过程里了,<br>方便修改,
 
我能理解<br>我的意思是:实现这样效果有没有简单的方法<br>porder &nbsp; code &nbsp;name &nbsp;klotvalue bunr &nbsp; bumo &nbsp; &nbsp;kvol &nbsp; ndate &nbsp; &nbsp;fdate &nbsp; &nbsp; jitu0<br>A001 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; AB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1200<br>A002 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; AB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060902 20060922 &nbsp;1500<br>合计 &nbsp; &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2700<br>A009 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; CB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1200<br>A010 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; CB &nbsp; &nbsp;ABC &nbsp; &nbsp; &nbsp;T5 &nbsp; &nbsp; MC736 &nbsp; 1000 &nbsp; 20060901 20060920 &nbsp;1100<br>合计 &nbsp; &nbsp; &nbsp;C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2300
 
关注 这个控件的使用 &nbsp;。看看大家的方法了
 
自己写代码控制吧。。
 
像此问题,我是采用内存表操作来实现的
 
学习,dyb_23能不能详细说一下?
 
dyb_23你说的是临时有吗
 
其实,如果是sql数据库的话,用一个存储过程就能轻松搞定
 
接受答案了.
 

Similar threads

J
回复
7
查看
361
jackson_wu
J
顶部