Null value in SQL test code _mssql

Source: Internet
Author: User
Tags modifier
Just wanted to retrieve those records from the table expert_details in the database whose modifier (type VARCHAR2 (20), nullable) are empty because the field is of type VARCHAR2 (20), and the SQL statement I use is
Copy Code code as follows:

SELECT * from expert_details twhere t.modifier = '

A record was not retrieved, which does not match the records stored in the table. It was later thought that even a null-character store in a database should be null instead of '.

I then used the following SQL statement and still did not retrieve a single record.
Copy Code code as follows:

SELECT * FROM Expert_details t
where t.modifier = null

Finally I thought of the null value test in SQL. Use the following statement to finally retrieve the desired result.
Copy Code code as follows:

SELECT * FROM Expert_details t
where t.modifier is null

In the SQL statement, WHERE clause: where t.modifier = null, the NULL keyword cannot be used here because it is not a true value, it is just a symbol because its value is unknown. When the t.modifier itself is NULL, the WHERE clause is: where null= null, when the values on both sides of the equals sign are unknown, the result is true or false,sql cannot give a definite result, so the result of the query is null.

Therefore, it is necessary to explicitly use a null value test that is null or a negative form field is not NULL to detect null values.

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.