日期:2014-05-18  浏览次数:20478 次

这样写别名为什么不对呢
SQL code

            insert [tb_订单] ([订单号], [总金额]) values([a].[订单号], [a].[总金额])
            from (select * from (select [订单号],sum([需求数量] * [单价]) as [总金额] from [tb_订单明细] where ([订单号] = @Order)
            group by [订单号]) as [a])    



------解决方案--------------------
group by 后面不能加别名,否则语法错误
ORDER BY 后面可以加别名。
------解决方案--------------------
看错了,不好意思
------解决方案--------------------
SQL code
      insert [tb_订单] ([订单号], [总金额]) 
  select [订单号],sum([需求数量] * [单价]) as [总金额] from [tb_订单明细] where ([订单号] = @Order
  group by [订单号]

------解决方案--------------------
SQL code
values([a].[订单号], [a].[总金额])

------解决方案--------------------
SQL code
你的语法也有问题。
直接这样写 
insert [tb_订单] select [订单号],sum([需求数量] * [单价])  from [tb_订单明细] where [订单号] = @Order
        group by [订单号]

------解决方案--------------------
探讨

SQL code
你的语法也有问题。
直接这样写
insert [tb_订单] select [订单号],sum([需求数量] * [单价]) from [tb_订单明细] where [订单号] = @Order
group by [订单号]

------解决方案--------------------
先去学习下UPDATE基本语法格式吧
------解决方案--------------------
SQL code
            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 [订单号]
楼主你的代码可以精简成这样,你执行下看看。