create proc sp_test
as
begin
select
sum(AllOCQTY) as [sum],
sum(case when Status=2 then AllOCQTY else 0 end) as [sum2]
from
(
select ALLOCQTY,Status from TABLE1
UNION ALL
select ALLOCQTY,Status from TABLE
)A
end
go
现在有2个结构相同的表。TABLE1,TABLE
其中有两个字段ALLOCQTY ,Status。 ALL字段中放的是整型数据。
现在要一个存储过程,ALL字段的SUM值与Status=2的ALL字段的值分别计算并返回。
要求在一个存储过程中实现。本人刚刚接触存储过程,那位高手帮下忙?
==
select
sum(AllOCQTY) as [sum],
sum(case when Status=2 then AllOCQTY else 0 end) as [sum2]
from
(
select ALLOCQTY,Status from TABLE1
UNION ALL
select ALLOCQTY,Status from TABLE
)A