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.. - SELECT C.CLIENTCODE, S.COMPANY, D.DEPTCODE, T.TEAM, P.PROJECTCODE, S.INVOICEDATE, S.INVOICENO, S.INVOICEPARTICULARS, S.INVOICEAMT, R.RECEIVEDAMT,
-
(SUM(S.INVOICEAMT) - SUM(R.RECEIVEDAMT)) AS [YET TO RECEIVE]
-
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
-
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
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?
NeoPa 32,556
Expert Mod 16PB
The answer to your actual question, would be : - SELECT S.COMPANY
-
, S.INVOICEDATE
-
, S.INVOICENO
-
, S.INVOICEPARTICULARS
-
, S.INVOICEAMT
-
, Sum(R.RECEIVEDAMT) AS Received
-
, (S.INVOICEAMT - [Received]) AS [YET TO RECEIVE]
-
-
FROM SALES AS S
-
LEFT JOIN
-
RECEIPTS AS R
-
ON S.INVOICEID = R.INVOICEID
-
-
GROUP BY S.COMPANY
-
, S.INVOICEDATE
-
, S.INVOICENO
-
, S.INVOICEPARTICULARS
-
, 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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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.)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |