怎样将b表中所有字段cWhCode数据相同的iQuantity相加,并将相加的结果加入到重新建立的a表中?

dxlth 2003-04-03 11:38:47
例如:
表a
iIsId int identity (1,1) not null,
cCode varchar(20) not null ,
cName varchar(40) null ,
benyueqichu float default 0 ,
benyueruku float default 0 ,
benyuechuku float default 0 ,
benyueleft float default 0 )
表b
iIsId int identity (1,1) not null,
dDate DateTime not null ,
cMth varchar(6) not null ,
cOrderNo varchar(12) not null ,
dInDate DateTime null ,
iLineNo int not null ,
cCaseNo varchar(20) null ,
cCode varchar(20) not null ,
cName varchar(40) null ,
cStd varchar(30) null ,
cUnit varchar(10) null ,
iQuantity float default 0 ,
iOutQty float default 0 ,
iBalQty float default 0 ,
iPrice float default 0 ,
cWhCode varchar(20) null ,
cWhName varchar(40) null ,
cPrdCCode varchar(10) null ,
cPrdCName varchar(40) null ,
cInType varchar(10) null ,
cRemark varchar(60) null )

...全文
72 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-04-03
  • 打赏
  • 举报
回复
重新建立的a:
select iIsId int identity(1,1),cCode,cName,sum(iQuantity) benyueqichu,0 benyueruku,0 benyuechuku,0 benyueleft into 表a from 表b where group by cCode

??
happydreamer 2003-04-03
  • 打赏
  • 举报
回复
insert a(cCode,用哪个字段啊)
select cCode,sum(iQuantity) from b group by cCode
misfans 2003-04-03
  • 打赏
  • 举报
回复
declare curCount cursor for
select cWhCode,sum(iQuantity) as count from b group by cWhCode
declare @vcWHCode varchar(20),@viQuantityf float
open curCount
fetch next from curCount into vcWhCode,@viQuantity
insert into a ...
fetch next from curCount into vcWhCode,@viQuantity
close curCount

ok?
愉快的登山者 2003-04-03
  • 打赏
  • 举报
回复
insert into A (cCode, benyueruku)
select cCode, sum(iQuantity) from B group by cCode
ben988211 2003-04-03
  • 打赏
  • 举报
回复
insert into a select cWhCode,'',iQuantity,0,0,0 from (select cWhCode,sum(iQuantity) as iQuantity from b group by cWhCode) c
dxlth 2003-04-03
  • 打赏
  • 举报
回复
是b表中所有字段cCode数据相同的iQuantity相加,并将相加的结果加入到重新建立的a

是cCode不是cWhCode
caiyunxia 2003-04-03
  • 打赏
  • 举报
回复
update a set benyueqichu = iQuantity from
(select cCode,sum(iQuantity) as iQuantity from a group by cCode) c
where a.ccode=c.code

insert into a(...)
select ...
from (select cCode,sum(iQuantity) as iQuantity from a group by cCode) c
left a
on a.ccode=c.code
where a.ccode is null
leimin 2003-04-03
  • 打赏
  • 举报
回复
insert into a(culumnname...)
select cCode,sum(iQuantity) from b group by cCode

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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