1
试图做一个WHERE BETWEEN
与CASE WHEN
:错误牛逼的Sql案例的情况下,使用之间时where子句
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
结果:
Msg 156, Level 15, State 1, Line 57
Incorrect syntax near the keyword 'and'.
您收到了什么错误? –
Msg 156,Level 15,State 1,Line 57 关键字'和'附近的语法不正确。 – Wilest