SQL Server ISNULL function and SQL statement for determining whether the value is null

Source: Internet
Author: User
Tags sql server isnull

Useful first

Copy codeThe Code is as follows:
Use Database
Update news set author = 'jb51 'where author is null


If you are incorrect, it means that you have made a mistake. Taking a closer look, we strongly recommend that you back up the database before performing operations.

Note: replace NULL with the specified replacement value.

Syntax: ISNULL (check_expression, replacement_value)

Parameters:

Check_expression: The expression to be checked for NULL. Check_expression can be of any type.

Replacement_value: The expression to be returned when check_expression is NULL. Replacement_value must be a type that can be implicitly converted to the check_expresssion type.

Return Value: returns the same type as check_expression.

NOTE: If check_expression is not NULL, its value is returned. Otherwise, the former is returned after the replacement_value is implicitly converted to the check_expression type (if the two types are different.

Instance:

Copy codeThe Code is as follows:
Select avg (ISNULL (Weight, 50 ))
FROM Production. Product;

Analysis:

Do not use ISNULL to find NULL values. Instead, use is null. The following example finds all products with NULL in the weight column. Note the space between IS and NULL.

Copy codeThe Code is as follows:
USE AdventureWorks2008R2;
GO
SELECT Name, Weight
FROM Production. Product
WHERE Weight is null;
GO


SQL Server: how to determine whether a variable or field is NULL

Judge whether the variable is NULL:

IF (@ VaribleName is null)


Select a record whose field value is NULL:

WHERE COLUMN_NAME IS NULL


ISNULL () function:

ISNULL (@ VaribleName, 'defaultvalue ')
ISNULL (COLUMN_NAME, 'default value ')

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.