Today when writing SQL code to write a ISNULL (variable 1, variable 2), the return of the result is actually "*", the asterisk, depressed for a long time.
The code has the following effect:
Declare @str1 varchar (1) Declare @str2 int Set @str2 = 222 Select ISNULL (@str1,@str2)
Return the result: "*", this depressed ah.
Modify the following code:
Declare @str1 varchar (4) Declare @str2 int Set @str2 = 222 Select ISNULL (@str1,@str2)
Returns the result: "222".
Modify the code again:
Declare @str1 varchar (4) Declare @str2 varchar (8) Set @str2 = ' 2222222 ' Select ISNULL (@str1,@str2)
Returns the result: "2222".
After these three test results: guessing the type of result returned by IsNull is closely related to the first variable, even depending on the type of the first variable.
Official explanation:
Syntax
Arguments
-
Check_expression
-
Is the expression to being checked for NULL. check_expression can is of any type.
-
Replacement_value
-
is, the expression to being returned if check_expression is NULL. Replacement_value must be of a type, that's implicitly convertible to the type of check_expresssion.
Return Types
Returns the same type as check_expression.
Remarks
The value of check_expression is returned if it was not NULL; Otherwise, Replacement_value was returned after it was implicitly converted to the type of check_expression , if the types is different.
The return value is the second argument, which turns to the type of the first argument, the conversion fails, the exception is reported, or the preceding "*", the asterisk, appears.
The isnull problem in SQL.