1

WHERE BETWEENで aを実行しようとしていますCASE WHEN:

SET @Qtr1 = datepart(MONTH,@dt1)
select 
SUM(QtyInvoiced) as QtrCase
,CustName
,Town
,Rep
from SalesSumNew 
where
FinMonth between
case when @Qtr1 between '1' and '3' THEN '10' and '12'
,case when @Qtr1 between '4' and '6' THEN '1' and '3'
,case when @Qtr1 between '7' and '9' THEN '4' and '6'
,case when @Qtr1 between '10' and '12' THEN '7' and '9'
end
group by CustName, Town, Rep
order by Town

エラーが発生します:

メッセージ 156、レベル 15、状態 1、行 57
キーワード「and」付近の構文が正しくありません。

4

1 に答える 1

3

You can't do that.

Try calculating the range using maths and mod : something like...

where FinMonth between 
((((2+@qtr1)/3)+2)*3)%12+1,
and
((((2+@qtr1)/3)+2)*3+2)%12+1

And if your FinMonth is really a string field, then '10','11','12' are all between '1' and '3'

于 2012-08-24T09:26:01.530 に答える