我有一张类似于下面的表格
Date |field1 | qty1 | qty2 | qty3
1 Aug | xyz | 0 | 0 | 3
1 Aug | xyz | 3 | 0 | 0
1 Aug | abc | 0 | 5 | 0
2 Aug | abc | 0 | 15 | 0
2 Aug | xyz | 0 | 12 | 0
2 Aug | xyz | 5 | 0 | 0
我编写了三个存储过程来分别显示每个数量,如下所示。
这是我的第一个程序
create procedure firstprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty1) as XYZ,
sum (case when field1 = 'abc', qty1) as ABC
from table1
where date between @startdate and @enddate
group by date
这是我的第二个程序
Create procedure secondprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty2) as XYZ,
sum (case when field1 = 'abc', qty2) as ABC
from table1
where date between @startdate and @enddate
group by date
这是我的第三个程序
Create procedure thirdprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty3) as XYZ,
sum (case when field1 = 'abc', qty3) as ABC
from table1
where date between @startdate and @enddate
group by date
我想知道我是否有机会将列(无论是 qty1、qty2 还是 qty3)放在参数中,并且在执行时只需提及我想要 qty1 还是 qty2 或 qty3。它应该相应地产生输出。