473,414 Members | 1,980 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,414 software developers and data experts.

Sum of row values

29
Hi,

I have two tables in MSACCESS.
1. Sales
2. Receipts

Whatever be the sale I will raise invoice which consists of unique invoice no.

after raising invoice I may receive the payment either full cash or in installment basis.

in this case the scenario is In SALES table - invoice number will be unique. whereas in RECEIPT table invoice number will be repeated which has invoice id as reference from sales table

Now problem starts here. I need to generate a report of invoice amount, received amount and yet to receive amount

I have 208 entries in sales table and 117 entries in receipts table

now my query need to generate only 208 rows which must have all the values of sales table and matching invoiceid of receipt table. but in receipt table invoice id will be multiple I need to sum up all the values of same invoiceid and bring it as one record so that I get only 208 records as a report

This is the query I have written: This must return only 208 rec instead it returns 212 rec because it is not summing up the receivedamt which consists of same invoiceno..

Expand|Select|Wrap|Line Numbers
  1. SELECT C.CLIENTCODE, S.COMPANY, D.DEPTCODE, T.TEAM, P.PROJECTCODE, S.INVOICEDATE, S.INVOICENO, S.INVOICEPARTICULARS, S.INVOICEAMT, R.RECEIVEDAMT,
  2. (SUM(S.INVOICEAMT) - SUM(R.RECEIVEDAMT)) AS [YET TO RECEIVE]
  3. FROM ((((SALES AS S LEFT JOIN RECEIPTS AS R ON S.INVOICEID = R.INVOICEID) INNER JOIN PROJECTS AS P ON S.ProjectID = P.ProjectID) INNER JOIN CLIENTELE AS C ON P.ClientID = C.ClientID) INNER JOIN TEAM AS T ON P.TeamID = T.TeamID) INNER JOIN DEPARTMENT AS D ON T.DeptID = D.DeptID
  4. GROUP BY C.CLIENTCODE, S.COMPANY, D.DEPTCODE, T.TEAM, P.PROJECTCODE, S.INVOICEDATE, S.INVOICENO, S.INVOICEPARTICULARS, S.INVOICEAMT, R.RECEIVEDAMT;
How will i achieve this report using a single query...

Thanks in advance
Oct 5 '10 #1
2 1985
NeoPa
32,556 Expert Mod 16PB
Your question doesn't match the SQL you posted. No wonder you have had no response yet. How do the [Projects], [Clientele], [Team] and [Department] tables fit into the requirement?
Oct 5 '10 #2
NeoPa
32,556 Expert Mod 16PB
The answer to your actual question, would be :
Expand|Select|Wrap|Line Numbers
  1. SELECT   S.COMPANY
  2.        , S.INVOICEDATE
  3.        , S.INVOICENO
  4.        , S.INVOICEPARTICULARS
  5.        , S.INVOICEAMT
  6.        , Sum(R.RECEIVEDAMT) AS Received
  7.        , (S.INVOICEAMT - [Received]) AS [YET TO RECEIVE]
  8.  
  9. FROM     SALES AS S
  10.          LEFT JOIN
  11.          RECEIPTS AS R
  12.   ON     S.INVOICEID = R.INVOICEID
  13.  
  14. GROUP BY S.COMPANY
  15.        , S.INVOICEDATE
  16.        , S.INVOICENO
  17.        , S.INVOICEPARTICULARS
  18.        , S.INVOICEAMT;
When we see what your question should have been we can hopefully move on, but putting it basically, you could use this SQL within a sub-query (See Subqueries in SQL), to handle mixing this with other tables.
Oct 5 '10 #3

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

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
1
by: Sue Adams | last post by:
I have a form on an asp page and am trying to write the code to place the values of all checkboxes that have been selected, into an array. The checkbox values will be used in a dynamic sql statement...
5
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
4
by: Steve Hall | last post by:
Folks, My secnario involves two tables - ObservationRegister, and Person. ObservationRegister contains most of the "useful" fields, including the UserID of the person that raised the record, and...
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
13
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! With VALUES you can do something like: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER) which will give you: LETTER NUMBER ------ ------ A 1 B 2...
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.