Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ISNULL to execute null value judgment query in SQL Server

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

SQL Server how to use ISNULL to execute null value judgment query, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

There is the following query: the copy code is as follows: select isnull (lastchanged,'') as lastchanged from vhhostlist where slots commentaries testing 202'

Originally, the ISNULL function has only one parameter, which means to determine whether the value of this parameter is NULL. If it is NULL, it returns TRUE, otherwise it returns FALSE.

However, in the query statement of SQLServer, isnull requires two parameters, which means that if parameter 1 is NULL, then parameter 2 is the return value of the isnull function

That is, the meaning of the above query is to query the value of the lastchanged field in the row lastchanged in the vhhostlist table, and if it is NULL, an empty string is returned

I remember that when I didn't understand this before, I encountered such a situation: an order form, one of the fields is status, and the status is NULL when the order is submitted. To make the following judgment in the program, when it is NULL, display an approved hyperlink; when it is not empty, display a string: approved. The program at that time was written as follows: the copy code is as follows: if rs ("status") "then response.write" audited "else response.write" audited "end if"

In fact, such a judgment is careless. Rs ("status") "" does not mean that rs ("status") has been audited, nor does it mean that anything other than rs ("status") "" is unexamined.

The most reasonable thing should be to use isnull (status,'') as status to find out the status. If rs ("status") = "", it means that it has not been tried. This must be true!

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report