Use ISNULL in SQL Server to perform null value judgment queries _mssql

Source: Internet
Author: User
Tags sql server query

There are the following inquiries:

Copy Code code as follows:

Select IsNull (lastchanged, ') as lastchanged from vhhostlist where s_comment= ' test202 '

Originally, the ISNULL function has only one argument, which means to determine whether the value of this parameter is NULL, is NULL to return True, otherwise return false;

However, in SQL Server query statements, ISNULL requires two parameters, meaning that if parameter 1 is null, then parameter 2 is the return value of the IsNull function;

That is, the meaning of the query above is to query the value of the LastChanged field in the s_comment= ' test202 ' row in the Vhhostlist table, and return an empty string if it is null;

I remember when I did not understand this, encountered a situation: an order form, one of the fields is status, the order submitted when the status is null. In the program to make the following judgment, when it is null, display an audited hyperlink; when it is not empty, a string is displayed: already audited. The procedure was written in this way:

Copy Code code as follows:

If RS ("status") <> "then"
Response.Write "<span style= ' color:red; ' > Audit </span> "
Else
Response.Write "<a href=check.asp?id=" & RS ("id") & "> Audit </a>"
End If

In fact, such judgments are not prudent, RS ("status") <> "" does not mean that the RS ("status") is equal to have been audited, nor does it mean that RS ("status") <> "" Outside the situation is the state of the trial;

The most reasonable should be to use ISNULL (status, ') as status to check out the status, if the RS ("status") = "" is not the trial, this is certain to set up!

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.