473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calcuation Error in Select Query

8
I have created a database for Payments entry for various parties in which I have created a Select Query for obtaining the Bill Details (Advance, Running & Final Bills) such as Bill value, Advance Paid, Bill Accounted, TDS, WCT, Balance Payable. I have given calculations based on Bill Value(s) in this query for all these bills (Advance, Running & Final Bills).

When I enter Bill Values for all Advance, Running Bills details only It is showing the Value in "Advance Paid" coloumn. Whereas if I enter the Bill Values in only in Advance Bill, there is no display in "Advance Paid" coloumn in the Final Bill Value section. I have given the calculation for obtaining the "Advance Paid" coloumn in the Final Bill section like this:
Adv Paid 3rd RA(Gross): CCur([Party Payments].[Advance Bill Value])+([1st RA Bill Accounted])+([2nd RA Bill Accounted])+([3rd RA Bill Accounted]).

Pls help on this.
Jul 3 '09 #1
6 1527
Stewart Ross
2,545 Expert Mod 2GB
When adding values you need to be careful about null entries - these can cause errors if a null is fed to a type conversion function such as CCur, for example, and nulls do not fit with arithmetic or other calculated operations - the null propagates, and adding a null to anything results in a null. Your CCur (type conversion to Currency) is covering the first field only - the others are not in its scope.

To avoid this, use Nz on each field and enclose the whole calculation within the CCur:

Expand|Select|Wrap|Line Numbers
  1. Adv Paid 3rd RA(Gross): CCur(Nz([Party Payments].[Advance Bill Value], 0) + Nz([1st RA Bill Accounted], 0)+Nz([2nd RA Bill Accounted], 0)+Nz([3rd RA Bill Accounted], 0))
Nz returns the specified text if a null value is encountered - 0 in this case. Null values in numeric fields or textboxes will not propagate if you use Nz to replace them with 0s or some other value as appropriate.

-Stewart
Jul 5 '09 #2
cvgope
8
Sir, I tried what you said by prefixing/using NZ, but still the problem remains the same. Is there any other way of getting the result?
Jul 6 '09 #3
Stewart Ross
2,545 Expert Mod 2GB
It would help if you could post the up-to-date statement you are using for your calculation. It would also help if you could post the SELECT statement you are referring to in post 1; I am not sure what relation these have to each other, but the more information you can give us to work on the better.

-Stewart
Jul 6 '09 #4
cvgope
8
Sir, a Select Query containing Details such as Bill value, Advance Paid, Bill Accounted, TDS, WCT,Balance Payable for Adv.Bill, 1st RA Bill, 2nd RA Bill, 3rd RA Bill & Final Bill.

I have given calculations based on Bill Value(s) for obtaining Bill Accounted, TDS, WCT & Balance Payable for all the Bills(1st, 2nd, 3rd RA & Final Bills).

I am getting all the calculation right except in the "Advance Paid" coloumn where I am supposed to get the total of all Advances Paid (beginning from Advance Bill to Final Bill). If I enter bill values in all corresponding Bill Sections (created individual Subforms for all RA Bills & Final Bills) only, the Total is displaying in all the subforms whereas if I enter Bill values only for 2 Bills (For example in Advance & 2nd RA Bill), the Total of Advances paid till the previous bill is not showing in the coloumn "Advance Paid". The following is the calculation I have given for each bill(s):

The SELECT Query is named as Party Payment Details. The following is the SQL Query: (Although the entire content below is given in one query, I have divided the query bill wise here for easy understanding, if i am right).

SELECT [Party Payments].OrderID, [Party Payments].[Advance Bill Value], CCur(Nz([Party Payments].[Advance Bill Value],0)*2.266/100) AS [TDS on Adv Bill], CCur(Nz([Party Payments].[Advance Bill Value],0)-Nz([TDS on Adv Bill],0)) AS [Net Adv Payable], [Party Payments].[Cheq/DD No], [Party Payments].[Cheq/DD Date],

[Party Payments].[1st RA Bill No], [Party Payments].[1st RA Bill Value], CCur(Nz([Advance Bill Value],0)) AS [Adv Paid(Gross)], CCur(Nz([Party Payments].[1st RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)) AS [1st RA Bill Accounted], CCur(Nz([1st RA Bill Accounted],0)*2.266/100) AS [TDS on 1st RA], CCur(Nz([1st RA Bill Accounted],0)*4/100) AS [WCT on 1st RA], CCur(Nz([1st RA Bill Accounted],0)*5/100) AS [5% on 1st RA], CCur(Nz([Party Payments].[1st RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([TDS on 1st RA],0)-Nz([WCT on 1st RA])-Nz([5% on 1st RA],0)) AS [1st RA Payable], [Party Payments].[Cheq/DD No(1st RA)], [Party Payments].[Cheq/DD Date(1st RA)],

[Party Payments].[2nd RA Bill No], [Party Payments].[2nd RA Bill Value], CCur(Nz([Party Payments].[Advance Bill Value],0)+Nz([1st RA Bill Accounted],0)) AS [Adv Paid 1st RA(Gross)], CCur(Nz([Party Payments].[2nd RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([1st RA Bill Accounted],0)) AS [2nd RA Bill Accounted], CCur(Nz([2nd RA Bill Accounted],0)*2.266/100) AS [TDS on 2nd RA], CCur(Nz([2nd RA Bill Accounted],0)*4/100) AS [WCT on 2nd RA], CCur(Nz([2nd RA Bill Accounted],0)*5/100) AS [5% on 2nd RA], CCur(Nz([Party Payments].[2nd RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([TDS on 2nd RA],0)-Nz([WCT on 2nd RA])-Nz([5% on 2nd RA],0)-Nz([1st RA Bill Accounted],0)) AS [2nd RA Payable], [Party Payments].[Cheq/DD No(2nd RA)], [Party Payments].[Cheq/DD Date(2nd RA)],

[Party Payments].[3rd RA Bill No], [Party Payments].[3rd RA Bill Value], CCur(Nz([Party Payments].[Advance Bill Value],0)+Nz([1st RA Bill Accounted],0)+Nz([2nd RA Bill Accounted],0)) AS [Adv Paid 2nd RA(Gross)], CCur(Nz([Party Payments].[3rd RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([1st RA Bill Accounted],0)-Nz([2nd RA Bill Accounted],0)) AS [3rd RA Bill Accounted], CCur(Nz([3rd RA Bill Accounted],0)*2.266/100) AS [TDS on 3rd RA], CCur(Nz([3rd RA Bill Accounted],0)*4/100) AS [WCT on 3rd RA], CCur(Nz([3rd RA Bill Accounted],0)*5/100) AS [5% on 3rd RA], CCur(Nz([Party Payments].[3rd RA Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([1st RA Bill Accounted],0)-Nz([2nd RA Bill Accounted],0)-Nz([TDS on 3rd RA],0)-Nz([WCT on 3rd RA],0)-Nz([5% on 3rd RA],0)) AS [3rd RA Payable], [Party Payments].[Cheq/DD No(3rd RA)], [Party Payments].[Cheq/DD Date(3rd RA)],

[Party Payments].[Final Bill No], [Party Payments].[Final Bill Value(75%)], [Party Payments].[Excess Qty], CCur(Nz([Party Payments].[Final Bill Value(75%)],0)-Nz([Party Payments].[Excess Qty],0)) AS [Amt Before Prorata], CCur(Nz([Amt Before Prorata],0)*75/100) AS [Pro Rata Value], CCur(Nz([Party Payments].[Advance Bill Value],0)+Nz([1st RA Bill Accounted],0)+Nz([2nd RA Bill Accounted],0)+Nz([3rd RA Bill Accounted],0)) AS [Adv Paid 3rd RA(Gross)], CCur(Nz([Pro Rata Value],0)-Nz([Adv Paid 3rd RA(Gross)],0)) AS [Pro Rata Accounted], CCur(Nz([Pro Rata Accounted],0)*2.266/100) AS [TDS on Final Bill(75%)], CCur(Nz([Pro Rata Accounted],0)*4/100) AS [WCT on Final Bill(75%)], CCur(Nz([Pro Rata Accounted],0)*5/100) AS [5% on Final Bill(75%)], CCur(Nz([Pro Rata Accounted],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([TDS on Final Bill(75%)],0)-Nz([WCT on Final Bill(75%)],0)-Nz([5% on Final Bill(75%)],0)-Nz([1st RA Bill Accounted],0)-Nz([2nd RA Bill Accounted],0)-Nz([3rd RA Bill Accounted],0)-Nz([Excess Qty],0)) AS [Final Bill(75%) Payable], [Party Payments].[Cheq/DD No(Pro-rata)], [Party Payments].[Cheq/DD Date(Pro-rata)],

[Party Payments].[Final Bill Value], [Party Payments].[Audit Deductions], [Party Payments].[Other Misc Deductions], CCur(Nz([Party Payments].[Advance Bill Value],0)+Nz([1st RA Bill Accounted],0)+Nz([2nd RA Bill Accounted],0)+Nz([3rd RA Bill Accounted],0)+Nz([Pro Rata Accounted],0)) AS [Adv Paid 75%(Gross)], CCur(Nz([Party Payments].[Final Bill Value],0)-Nz([Pro Rata Accounted],0)-Nz([3rd RA Bill Accounted],0)-Nz([2nd RA Bill Accounted],0)-Nz([1st RA Bill Accounted],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([Party Payments].[Audit Deductions],0)-Nz([Party Payments].[Other Misc Deductions],0)) AS [Final Bill Accounted], CCur(Nz([Final Bill Accounted],0)*2.266/100) AS [TDS on Final Bill], CCur(Nz([Final Bill Accounted],0)*4/100) AS [WCT on Final Bill], CCur(Nz([Final Bill Accounted],0)*5/100) AS [5% on Final Bill], CCur(Nz([Party Payments].[Final Bill Value],0)-Nz([Party Payments].[Advance Bill Value],0)-Nz([TDS on Final Bill],0)-Nz([WCT on Final Bill],0)-Nz([5% on Final Bill],0)-Nz([1st RA Bill Accounted],0)-Nz([2nd RA Bill Accounted],0)-Nz([3rd RA Bill Accounted],0)-Nz([Pro Rata Accounted],0)-Nz([Party Payments].[Audit Deductions],0)-Nz([Party Payments].[Other Misc Deductions],0)) AS [Balance Payable], [Party Payments].[Cheq/DD No(Final)], [Party Payments].[Cheq/DD Date(Final)]
FROM Orders INNER JOIN [Party Payments] ON Orders.OrderID = [Party Payments].OrderID;
Jul 7 '09 #5
cvgope
8
Dear Mr.Stewart Ross

help me out with this problem. Its urgent. Dont think otherwise.
Jul 9 '09 #6
cvgope
8
I will be greatful if anybody sort this out and show me the solution. It is very urgent.
Jul 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
1
by: Kevin | last post by:
Help, I am running a pass through query to oracle from SQL server 2000 as follows; select * from openquery(nbsp, 'select * from FND_FLEX_VALUES') I have run this query through both DTS and...
3
by: Matias Silva | last post by:
Hi Everyone, I wrote a for loop to build several select statements that are combined with a UNION. When I execute one of the queries separately, it works, but when I execute the query with a UNION...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
4
by: MLH | last post by:
< < < VERY LOW PRIORITY POST > > > When I'm creating a query in the QBE grid whose SQL looks like this... INSERT INTO tblOwners (OwnerFName, OwnerLName, OwnerAddr, OwnerCity, OwnerState,...
2
by: frbn | last post by:
hi all, we currently experience an original problem on a production server with a postgresql 7.1.3 ( a bit old, I know :\ ) We just want to know if somebody experienced this problem: the...
4
by: Tony WONG | last post by:
i use the below formula to add up records which is extracted from SQL by ASP. sumQS = cint(objRS1("Q1S")) + cint(objRS1("Q2S")) + .... but if cint(objRS1("Q1S")) is null, it gets error. i...
5
by: Omer | last post by:
Hi, I am using C# 2.0 along with MS Access database. All my queries are working perfectly fine, but one inner join query is ocntinously throwing. I ahve tried it both from code and running...
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.