解决此问题,100分相送!

cmt123 2003-04-29 05:13:23
table1 str_C
G_Code G_Name G_Amount //字段名
a1 b1 23
a2 b2 32
. . .
. . .

Table2 STR_C
GCode GName GAmount //字段名
a1 b1 2
a1 b1 3
a2 b2 4
. . .
. . .

现在是判断Table2 中的GCode字段中的每一行, 如果与Table1中的G_Code字段的值相等,那么把Table2表中GCode字段对应的GAmount字段的值加到Table1表中G_Code字段对应的G_Amount中。(注:Table1表中的记录较多,我试了几种方法但速度不是很理想,但有些方法不能在DelPhi中成功运行)




...全文
24 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cmt123 2003-04-29
  • 打赏
  • 举报
回复
楼上的在SQL中能够成功运行,在Delphi中也可以运行,但不能更新G_Amount,不知是什么原因?
yuwu_zjl 2003-04-29
  • 打赏
  • 举报
回复
update table1 set table1.g_Amount=table1.g_Amount+table2.gAmount
from table1,table2
where table1.g_code=table2.gCode
sunkyling 2003-04-29
  • 打赏
  • 举报
回复
Declare table_cursor CURSOR For
select Table2.GAmount from table1,table2 where table1.G_code=table2.Gcode;
open table_cursor;
while @@FETCH_STATUS = 0
begin
fetch next from table_cursor into @GAmount
update table where table1.G_Amount=@GAmount
end
CLOSE table_cursor
DEALLOCATE table_cursor
sunkyling 2003-04-29
  • 打赏
  • 举报
回复
update Table1 set Table1.G_Amount=Table2.GAmount from Table1,Table2 where
Table1.G_code=Table2.Gcode;
liang_z 2003-04-29
  • 打赏
  • 举报
回复
速度不理想的关键是为建索引!
踢踏 2003-04-29
  • 打赏
  • 举报
回复
用Sql,未经测试。

select GCode, sum(Table1.GAmount)+sum(Table2.GAmount) as GAmout from Table1,Table2
where Table1.GCode=Table2.GCode
group by GCode

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧