时间:2021-07-01 10:21:17 帮助过:3人阅读
返回结果:" * ",这个郁闷啊。
修改下代码:
declare @str1 varchar(4) declare @str2 int set @str2=222 select ISNULL(@str1,@str2)
返回结果: " 222 " 。
再次修改代码:
declare @str1 varchar(4) declare @str2 varchar(8) set @str2=‘2222222‘ select ISNULL(@str1,@str2)
返回结果:" 2222 "。
经过这三次的试验结果:猜测isnull返回的结果类型,与第一个变量是息息相关的,甚至就取决于第一个变量的类型。
官方解释:
ISNULL ( check_expression , replacement_value ) |
Is the expression to be checked for NULL. check_expression can be of any type.
Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.
Returns the same type as check_expression.
The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.
返回值是第二个参数,会转成第一个参数的类型,转换失败,就会报异常或者出现前面的"*",星号。
SQL中ISNULL的问题。
标签: