ISNULL
Replace NULL with the specified replacement value.
Syntax
:ISNULL (check_expression, replacement_value)
Parameters
check_expression
The expression that will be checked to see if it is NULL
. If it is not NULL
, this value is returned directly, which is the expression check_expression
. If it is empty, this will directly return the content of replacement_value
. check_expression
can be of any type.
replacement_value
The expression that will be returned when check_expression
is NULL
. replacement_value
must be of the same type as check_expresssion
.
Return type
Returns the same type as check_expression
.
Notes
If check_expression
is not NULL, then return the value of the expression; otherwise, return replacement_value
.
Example
1 Sample data
The table tb_Student and its sample data are shown in the figure below.
2. Query requirements
Query the student information whose score is less than or equal to 60 and save it to the table variable @tempTable , when the student's score is empty, the score is recorded as 0.
declare @tempTable table( stuname nchar(10), stuage int, stuscore float); insert into @tempTable select name,age,ISNULL(score,0) from tb_Student where ISNULL(score,0)<=60 select * from @tempTable
3 Execution results
Recommended tutorial: "sql tutorial"
The above is the detailed content of Detailed explanation of sql isnull usage. For more information, please follow other related articles on the PHP Chinese website!