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 apply sqlserver isnull in Database query

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

Share

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

This article introduces you how to sqlserver isnull in the database query application, the content is very detailed, interested partners can refer to, I hope to help you.

isnull is used in database queries, especially when connecting statements. For example, when connecting, a field has no value, but if it is left connected to other tables, it will display null. isnull can determine whether it is NULL. If it is, give a default value isnull.("Field Name","Default Data") The three characteristics of null values and IsNull function NULL values in SqlServer are: 1) NULL values do not participate in statistics;2) NULL values do not enter calculation expressions; and 3) they cannot be compared with other values. The so-called NULL value does not participate in statistics, that is, when using statistical functions, everything involving NULL values will be ignored (the word may not be accurate), do not think that this is not important, in fact, in some places this is very important. The NULL value does not enter the calculation, that is to say, when performing statistical calculations between data, if there is an item with a NULL value, then it does not enter or participate in the calculation. This is also a problem that cannot be ignored. This is common even in life. For example, if a person's bonus is NULL (no data or other reasons are entered, no discussion will be made), and his basic salary will not be 0, right? (If it is 0, it has already been T). When calculating the total salary at the end of the month, add the bonus to the basic salary. If the bonus is NULL, the total salary = basic salary + bonus (NULL). Then when this happens, the total salary = basic salary? The affirmative answer is: not equal to. Since the bonus is NULL, what exactly does NULL represent? I don't know. If you don't know what NULL is, how can you calculate it? Therefore, the total wage equal to NULL is also uncertain. In this case, would there still be employees who dared to stay in the company? If you come to a total salary NULL is really empty, then what work ah?! This involves a casting problem, which is to cast NULL values to 0 to make them business meaningful. The keyword for coercion is IS, and the syntax is IS NULL; this allows calculations involving NULL values to be performed. However, NULL values do not affect all statistical functions. Generally speaking. For statistical averages (AVG), NULL values are bound to have an impact; for statistical minima (MIN), NULL values may have an impact on MIN, which I think is somewhat random; for statistical maxima (MAX) or statistical sums (NULL), NULL values have no impact at all. Therefore, there is another saying: null value does not participate in statistics, does not participate in calculations, can only be judged by is. Null value statement: select * from table where field is null; convert null value statement: select field 1, field 2, field 3, is null(field 3,'some value') from table; in short, we should take NULL values seriously, and it is best to add IS NULL when using statistical functions to prevent unexpected occurrences. The database has a column that records the number of times an article has been accessed. What I'm going to do now is, every time I refresh the page. Number of visits +1. sql statement,art_count is the number of accesses, int type. update article set art_count="(art_count+1) where art_id="3 but has no effect if art_count is NULL. If it is oracle, decode can easily implement this function. How to implement similar functionality in sqlserver? There is a function isnull in sqlserver, which takes two arguments isnull (p1, p2) and uses p2 instead if p1 is null. This function is similar to Oracle's NVL. For example SELECT AVG(ISNULL(price, $10.00)) FROM titles Inspired by this function, I write the sql statement update article set art_count="(isnull(vote_count,0)+1) where art_id="3 "

About how to carry out sqlserver isnull in the database query application to share here, I hope the above content can have some help for everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

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