I am writing a parameterised query where there is a requirement for the LIKE
clause to include NULL
values when field LIKE '%'
.
I have multiple solutions; I ran these queries side-by-side and they return the similar execution plans with the same summary and the query times are similar. I worry about how these queries scale-up in performance for tables with millions of records.
-- Where @PartId is typically '%' or could be 'Part123%'.
SELECT *
FROM dbo.OrderItems AS oi
WHERE oi.PartId IS NULL OR oi.PartId LIKE @PartId
SELECT *
FROM dbo.OrderItems AS oi
WHERE ISNULL(oi.PartId, '') LIKE @PartId
SELECT *
FROM dbo.OrderItems AS oi
WHERE COALESCE(oi.PartId, '') LIKE @PartId
This question suggests that there is very little difference between ISNULL
and COALESCE
. Grant Fritchey demonstrates in this article that applying functions on WHERE
clauses causes a bigger performance hindrance than using LIKE
, however I've read that using logical OR
can cause performance issues in queries. What is the performance impact with using IS NULL OR
vs. the alternative of ISNULL
?