开发者

Conditional Where statement syntax or some other solution

@MallUnit is a parameter with value 'Unit 401,Unit 402,Unit 403' I would like to have a conditional where statement. Assume that before the AND there are other conditions that work just fine. Basically, if ScheduledMallUnitTypeID is null evaluate using the IN condition. Otherwise, use the like clause.

AND
                CASE ScheduledMallUnitTypeID IS NULL THEN
                ScheduledMallUnitTypeID IN
                (       
                 SELECT Value 
                 FROM 开发者_JAVA技巧Toolbox.dbo.ReportingPortalMultiSetParameterFix(@MallUnit)
                )
                ELSE ScheduledMallUnitTypeID LIKE @MallUnit
                END


This would work:

WHERE
   ( ScheduledMallUnitTypeID IS NULL AND
     ScheduledMallUnitTypeID IN
                (       
                 SELECT Value 
                 FROM Toolbox.dbo.ReportingPortalMultiSetParameterFix(@MallUnit)
                )
   )
   OR
   (
     ScheduledMallUnitTypeID IS NOT NULL AND 
     ScheduledMallUnitTypeID LIKE @MallUnit
   )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜