Reputation: 6626
SELECT ...
FROM ...
WHERE CASE WHEN @ActivityUID = '00000000-0000-0000-0000-000000000000'
THEN
-- do nothing
ELSE
(Activity.ActivityUID = @ActivityUID)
END
When a blank Guid is passed in via ActivityUID then I want the WHERE statement to ignore Activity.ActivityUID = @ActivityUID
Upvotes: 1
Views: 1209
Reputation: 432210
This removes the need for an OR clause because NULL comparisons fail.
WHERE
Activity.ActivityUID = NULLIF(@ActivityUID, '00000000-0000-0000-0000-000000000000')
See if there is a performance difference...
Upvotes: 0
Reputation: 10092
WHERE (
Activity.ActivityUID = @ActivityUID OR
@ActivityUID = '00000000-0000-0000-0000-000000000000'
)
Upvotes: 3