For a table with a column ColA as VARCHAR(x), how should I rewrite this condition
ColA LIKE @param + '%'
taking into account that:
- 1/ ColA is NULLable.
- 2/ @param could be NULL
- 3/ There is an index on ColA, and it should be used for all searches
- 4/ Avoid sp_executesql as this is part of much larger stored proc
I was thinking at:
ISNULL(ColA, '') LIKE (CASE WHEN @param IS NULL THEN '%' ELSE @param + '%' END)
but this will not make use of index defined on ColA.