1

Not sure how to do this so was hoping that someone could help, I have a multivalue parameter we shall call 'Week', this has a drop down of 1 through to 4. My data set example is :-

select total from tableA where Week in (@Week)

what I want to do is divide the total by the number of options I pick from the drop down, e.g. if I picked Week 1 & 2, I would want the TSQL statement to use the count of 2 as the value to divide by e.g.

select total/2 from tableA where Week in (@Week)

is this possible?

Thanks P

4

2 に答える 2

2

平均関数の使用を検討してください。

SELECT AVG(total) FROM tableA WHERE Week IN(@Week)
于 2013-07-09T13:14:25.140 に答える
1

ユーザー定義の分割関数を使用して、複数値パラメーターをテーブル内の行に変換します。これらは何度か投稿されています。次に、次のようなことを簡単に行うことができます。

select sum(A.total), count(distinct Weeks.items)
from tableA as A
inner join dbo.Split(@week) as Weeks on Weeks.items = A.Weeks
于 2013-07-09T15:31:21.020 に答える