My curiosity always gets the best of me and I've searched online for an explanation to this and came up with nothing (could be because I didn't use the right terms.)
Can someone please explain why SQL Server returns a value of zero (0) when the following is executed, instead of an empty string ('').
DECLARE @I AS INT
SET @I = NULL
SELECT ISNULL(@I, '') -- 0
As declared here, the second argument to ISNULL
is the replacement_value, which "must be of a type that is implicitly convertible to the type of check_expresssion." Implicitly converting ''
to INT
results in 0.
Because @I is declared as an INT
, the empty string is implicitly CAST as an integer resulting in a ZERO.
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