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
)
精彩评论