Sum of null values in SQL

Source: Internet
Author: User

Recently, when I was working on a data center charging system, I encountered a form: Daily Statement.

Here, you need to determine the daily Recharge Amount, consumption amount, and refund amount. I calculated the data while loading the form. But how to calculate these problems. This is what I writeCodeOf:

 
Strtxtsql = "select sum (addmoney) from recharge_info where date = '" & A1 &"'"
 
Set mrca = executesql (strtxtsql, strmsgtext)
 
B = mrca. Fields (0)
 
Mrca. Close

I thought it was a very simple thing. During the operation, an error always occurred, and "invalid null value" was displayed ".

I copied the code in VB to SQL for query. The query is displayed as null.There is no Recharge Amount on the current day, and an error occurs when the null value is passed to B and the other number is added. Now I think of the isnull function, and the code is changed to the following:

 
Strtxtsql = "select sum (addmoney) from recharge_info where date = '" & A1 & "'" set mrca = executesql (strtxtsql, strmsgtext) If isnull (mrca. fields (0) then' if the displayed number is null, B = 0 else B = mrca. fields (0) end if mrca. close

This wayLet null value = 0The problem is easily solved.

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.