SQL Server: WHERE clause to ignore blank GUID
SELECT ...
FROM ...
WHERE CASE WHEN @ActivityUID = '00000000-0000-0000-0000-00000开发者_如何学JAVA0000000'
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
WHERE (
Activity.ActivityUID = @ActivityUID OR
@ActivityUID = '00000000-0000-0000-0000-000000000000'
)
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...
精彩评论