我具有類似於下面是否可以在存儲過程的參數中放置一個列名?
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 o r qty2或qty3。它應該產生相應的輸出。
如果可能的話,在繼續之前將表格標準化會更好。應該有一個列('qtytype'),用於存儲處理的數量類型('1','2'或'3'之一),然後是包含該值的* single *'qty'列。 – 2012-08-16 08:13:33