当前位置:Gxlcms > 数据库问题 > SQL中ISNULL的问题。

SQL中ISNULL的问题。

时间:2021-07-01 10:21:17 帮助过:3人阅读

@str1 varchar(1) declare @str2 int set @str2=222 select ISNULL(@str1,@str2)

返回结果:" * ",这个郁闷啊。

修改下代码:

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返回的结果类型,与第一个变量是息息相关的,甚至就取决于第一个变量的类型。

 

官方解释:

Syntax

 
ISNULL ( check_expression , replacement_value )

技术分享Arguments

check_expression

Is the expression to be checked for NULL. check_expression can be of any type.

replacement_value

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.

技术分享Return Types

Returns the same type as check_expression.

技术分享Remarks

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的问题。

标签:

人气教程排行