Use ISNULL in SQL Server to execute null value judgment query, serverisnull
The following queries are available:
Copy codeThe Code is as follows:
Select isnull (lastchanged, '') as lastchanged from vhhostlist where s_comment = 'test202'
Originally, the ISNULL function has only one parameter. It indicates that the parameter is used to determine whether the value of this parameter is NULL. If it is NULL, TRUE is returned; otherwise, FALSE is returned;
However, in the SQL Server query statement, isnull requires two parameters, which means that if parameter 1 is NULL, parameter 2 is the return value of the isnull function;
That is, the meaning of the preceding query is to query the value of the lastchanged field of s_comment = 'test202 'in the vhhostlist table. If it is NULL, an empty string is returned;
I remember that when I didn't understand this before, I encountered the following situation: one order table, one of which is status, and the status is NULL when the order is submitted. Make the following judgment in the program. When it is NULL, a review hyperlink is displayed; when it is not empty, a string is displayed: reviewed. At that time, the program was written as follows:
Copy codeThe Code is as follows:
If rs ("status") <> "then
Response. write "<span style = 'color: red; '> reviewed </span>"
Else
Response. write "<a href = check. asp? Id = "& rs (" id ") &"> review </a>"
End if
In fact, this judgment is not accurate. rs ("status") <> "does not mean that rs (" status ") is already reviewed; it does not indicate that the rs ("status") <> "is not audited;
The most reasonable one is to use isnull (status, '') as status to check the status. If rs (" status ") =" ", it indicates that the status is not reviewed. This must be true!
How can I determine whether a queried value is null in SQL server?
You cannot get the correct value because the result field has null.
This way
Select SUM (isnull (Result, 0) as Result from PDS_LabResultData
The isnull function is used.
Isnull (Result, 0) indicates that if result is null, the value is 0.
How can I judge that fields in the SQL SERVER table are empty?
In SQL server, 12:00:00 AM is also considered null ('', not null)