Null (NULL) retrieval of SQL Learning

Source: Internet
Author: User

In creating a table table, we can specify that the column package does not contain a value, and that when a column does not contain a value, we can say that it contains null values.

Determines whether the value is null and cannot be simply checked for =null. The SELECT statement has a special WHERE clause that you can use to examine columns that have null values. This WHERE clause is the IS NULL clause.

SELECT * FROM T_check_infodetail the following view:

This time we need to retrieve the checkvaluestring column as a null value, Resultremarks (the field is a blank record)

I'm going to write this code.

Select *  from where = NULL  and Resultremarks=' '

Then console error:

The data type text and varchar are incompatible in the equal to operator.

Check the following: text type query is not supported =, can support Like,nvarchar (max) data type is a new type, length is equal to text
The function of the text type is very special, so since the beginning of the general Big data type is defined as Max, discard the text, can only datalength (the field name is (resultremarks)) =0 to determine whether it is the length of zero is the field is empty!

So the code changes to this:

Select *  from where = NULL  and datalength (Resultremarks) = 0

And there was nothing, and this time we looked at the data. It is found that the null value ZAI the database has a special meaning, which is different from the field containing 0, an empty string, or simply containing a space.

So to determine whether a field is empty, you must also use a special WHERE clause is NULL, the code is as follows:

Select *  from where  is NULL  and datalength (Resultremarks) = 0

Ok!

Null (NULL) retrieval of SQL Learning

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.