日期:2014-05-18 浏览次数:20459 次
insert [tb_订单] ([订单号], [总金额]) values([a].[订单号], [a].[总金额]) from (select * from (select [订单号],sum([需求数量] * [单价]) as [总金额] from [tb_订单明细] where ([订单号] = @Order) group by [订单号]) as [a])
insert [tb_订单] ([订单号], [总金额]) select [订单号],sum([需求数量] * [单价]) as [总金额] from [tb_订单明细] where ([订单号] = @Order group by [订单号]
------解决方案--------------------
values([a].[订单号], [a].[总金额])
------解决方案--------------------
你的语法也有问题。 直接这样写 insert [tb_订单] select [订单号],sum([需求数量] * [单价]) from [tb_订单明细] where [订单号] = @Order group by [订单号]
------解决方案--------------------
UPDATE [TB_CASESUM] SET [订单号] = A.[订单号], [客户名称] = A.[客户名称], [总金额] = A.[总金额] FROM ( SELECT [订单号], [客户名称], SUM([需求数量] * [单价]) AS 总金额 FROM [TB_CASE] WHERE ([订单号] = @ORDER) GROUP BY [订单号], [客户名称] ) A WHERE ([订单号] = @ORDER);
------解决方案--------------------
不是别名的问题。
------解决方案--------------------
我是来看看的~~
------解决方案--------------------
insert into [tb_订单]
(
[订单号],
[总金额]
)
select [订单号],
sum([需求数量] * [单价]) as [总金额]
from [tb_订单明细]
where [订单号] = @Order
group by [订单号]
楼主你的代码可以精简成这样,你执行下看看。