SQL Server ISNULL function and whether the decision value is empty _mssql

Source: Internet
Author: User
Tags sql server isnull
It's useful first.

Copy Code code as follows:

Use database
Update news set author= ' jb51 ' where author is null


If you're not right, that means you've got a wrong call somewhere. With a closer look, it is strongly recommended that you back up the database before doing so.

Description: Replaces NULL with the specified replacement value.

Syntax: ISNULL (check_expression, Replacement_value)

Parameters:

Check_expression: An expression that will be checked for NULL. Check_expression can be of any type.

Replacement_value: An expression to return when Check_expression is NULL. Replacement_value must be a type that can be implicitly converted to a check_expresssion type.

Return value: Returns the same type as check_expression.

Note: If check_expression is not NULL, it returns its value, otherwise, the former is returned when Replacement_value is implicitly converted to the type of check_expression, if the two types are different.

Instance:

Copy Code code as follows:

SELECT AVG (ISNULL (Weight, 50))
From Production.Product;

Analysis:

Do not use ISNULL to find NULL values. Instead, you should use is NULL. The following example finds all products that have NULL in the weight column. Please note the space between IS and NULL.

Copy Code code 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

Determines whether a variable is null:

IF (@VaribleName is NULL)


Select a record for which the 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.