我有一个SP需要根据以下内容进行过滤:
....
where
and cs.chargetype = @chargetype
AND (@chargetype = 'Q' and
(@biweeklypart = 1 and datepart(dd,cs.scheduledate) = 15)
OR
(@biweeklypart = 1 and datepart(dd,cs.scheduledate) <> 15)
)
但是没有用。
我需要的是,只有当@chargetype = 'Q'
和@biweeklypart = 1
时,我必须按datepart(dd,cs.scheduledate) = 15
进行过滤,如果是@chargetype = 'Q'
和@biweeklypart = 2
那么我必须按datepart(dd,cs.scheduledate) <> 15
过滤。
有任何线索吗?我以为我做得对。
答案 0 :(得分:1)
根据您的说明,您需要:
where cs.chargetype = @chargetype and
( (@chargetype = 'Q' and @biweeklypart = 1 and day(cs.scheduledate) = 15) or
(@chargetype = 'Q' and @biweeklypart = 2 and day(cs.scheduledate) <> 15) or
(@chargetype <> 'Q')
)