Home > Database > SQL > Detailed explanation of sql isnull usage

Detailed explanation of sql isnull usage

hzc
Release: 2020-06-16 17:15:16
Original
5810 people have browsed it

Detailed explanation of sql isnull usage

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.

Detailed explanation of sql isnull usage

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
Copy after login

3 Execution results

Detailed explanation of sql isnull usage

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!

Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template