您好我的where子句中包含以下条件:
and ( ( datepart(mm,cs.scheduledate) <= @month and @accumulate = 1 )
or ( datepart(mm,cs.scheduledate) = @month and @accumulate = 0 ) )
因此,当@accumulate = 1
我希望过滤datepart(mm,cs.scheduledate) <= @month
时,如果我@accumulate = 0
,则希望按datepart(mm,cs.scheduledate) = @month
过滤
我做错了,因为它总是按datepart(mm,cs.scheduledate) = @month
有任何线索吗?
答案 0 :(得分:0)
我不清楚你在问什么,但我有一些想法可以尝试:
and ( ( datepart(mm,cs.scheduledate) < @month and @accumulate = 1 )
or ( datepart(mm,cs.scheduledate) = @month and @accumulate IN (0,1) ) )
或
and 1 = CASE WHEN datepart(mm,cs.scheduledate) = @month and @accumulate = 0 THEN 1
WHEN datepart(mm,cs.scheduledate) <= @month and @accumulate = 1 THEN 1
ELSE 0 END