Currently reviewing a stored procedure to which @return_count is a parameter. Below is a standalone example of the two ways that I can set its value if a NULL is passed in.
Cant figure out if the query optimizer would treat them the same or if one method is better than the other.
DECLARE @return_count int
SET @return_count = null
IF @return_count is null
BEGIN
SELECT @return_count = 10
END
GO
DECLARE @return_count int
SET @return_count = null
BEGIN
SELECT @return_count = 10
WHERE @return_count is null
END
You might want to consider
SELECT @return_count = ISNULL(@return_count, 10)
They return different exec plans, and the former is considerably less complex. The latter involves filter and scan operations. Since it doesn't appear that this needs to scale, I'd go with the former.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With