Is there a way to write the following script so that it returns all products if the ProductID variable is null ? And return a specific product when the product it is not nul
Performance is a incredible better when using CASE statement:
CASE
SELECT ProductID, ProductName,ProductDesc FROM product WHERE ProductID = CASE WHEN @productID IS NULL THEN ProductID ELSE @productID END
ISNULL() prevents the optimizer using an index on that column.
ISNULL()