SQL Server 2000:如何检索订单行的小计(汇总不存在)
问题描述:
当前在Crystal Report中,我将每个订单分组在一起,其中用户在订单组中显示订单行。SQL Server 2000:如何检索订单行的小计(汇总不存在)
我已经为所有订单行价格的小计制作了总计字段。但我想为最终用户设定一个参数,以选择价格是否为特定数量的>
或<
。
而我认为可能是最好的解决方案是计算存储过程中的小计,并将其传递给报告以构建参数。
但它看起来像SQL Server 2000不包含更高版本中的“ROLLUP”功能。
答
想通了:
select TS.Order_no, part_no, cost_per_line,
case when Order_no = (select top 1 Order_no from #tempsales
where cust_po = TS.cust_po
order by Order_no asc)
then (select sum(cost_per_line)
from #tempsales
where Order_no <= TS.Order_no
and cust_po = TS.cust_po)
else '0' end as 'Sub Total',
case when Order_no = (select top 1 Order_no from #tempsales
where cust_po = TS.cust_po
order by Order_no asc)
then (select CAST(ROUND(SUM(cost_per_line), 2, 1) AS DECIMAL(18, 2))
from #tempsales)
else '0' end as 'Grand Total'
from #tempsales TS
SQL Server 2000是***远远超出死*** - 它的干尸。现在是时候从这个**升级到现在的一个loooooooong时间了! –
是的,没有开玩笑...............不幸的是,我的公司正在从SQL 2000到2016年进行大规模升级,直到12月份,我基本上坚持了它,所以真的有一些帮助,而不是忽略问题很棒。 – tfenwick11