473,398 Members | 2,404 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,398 software developers and data experts.

Subtraction in Access Queries

Hi sorry if I am being a bit dumb but i am confused.

Currently I have a query which has 3 fields.

One has a product ID number

The next has Quantity purchased

(these both fields from tables)

The next has quantity sold. Now this one is made by adding up all the records with a given "product ID number" to get the quantity sold. Each incidence of the ID number adds 1 to the total.

So far so good. I have product ID's the quantity purchased and quantity sold.

I now what a further field that will substract the quantity sold(which is in the previous query field) from the quantity purchased to obtain quantity remaining.

If anyone could help it would be immensely appreciated.
May 1 '07 #1
10 13060
Denburt
1,356 Expert 1GB
From your post I am thinking that you are using a totals query so your results may not be what you expect. I am not real sure I understand but In a standard access query looking at the query in design view you have the fields to be viewed in the lower portion. If you add the following: MyRemQuant:[quantity purchased]-[quantity sold]

I hope this helps if not please post your SQL statement so I can understand a little better.
May 1 '07 #2
SELECT SW_INFO.SWI_ID, CST.CST_QTY, Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY
FROM (CST INNER JOIN SW_INFO ON CST.CST_ID = SW_INFO.SWI_CST_ID) INNER JOIN SW_SLS ON SW_INFO.SWI_ID = SW_SLS.SWS_SW_ID
GROUP BY SW_INFO.SWI_ID, CST.CST_QTY;


Thats the SQL i have currently.

What i want to do is have a field where i can substract:
"Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY"

From
"CST.CST_QTY"
May 1 '07 #3
" If you add the following: MyRemQuant:[quantity purchased]-[quantity sold]"

Where would i add this? Simply in the field box?
May 1 '07 #4
Right I tried Myremquant with
["CST.CST_QTY"]-[Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY]


It didn't work in as it said "invalid bracketing" or some such warning.
May 1 '07 #5
Denburt
1,356 Expert 1GB
Right I tried Myremquant with
["CST.CST_QTY"]-[Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY]


It didn't work in as it said "invalid bracketing" or some such warning.
Remove the quotes:

[CST.CST_QTY]-[Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY]
May 1 '07 #6
Thanks but unfortunately i tried that. It doesn't like the second term. The brackets within brackets apparently
May 1 '07 #7
"If you add the following: MyRemQuant:[quantity purchased]-[quantity sold]"

The problem is the "quantity sold" comes from the same query and is denoted by the following SQL. Its the sum of a the number of the field "SWS.QTY" from the "SW_SLS" table.

Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY

Anyone have any ideas how to construct this final field?
May 1 '07 #8
Denburt
1,356 Expert 1GB
O.K. to show you an example SQL I just created all I used was 1 table however it should work similarly for you as well, you should be able to see how I took the price field grouped it then in another field I added it up, in the third field I then subtracted them:

Expand|Select|Wrap|Line Numbers
  1. SELECT PRICEVALUELocal.PRICEINDEX, PRICEVALUELocal.PRICE, Sum(PRICEVALUELocal.PRICE) AS PRICE1,Sum(PRICEVALUELocal.PRICE)-[Price] AS P
  2. FROM PRICEVALUELocal
  3. GROUP BY PRICEVALUELocal.PRICEINDEX, PRICEVALUELocal.PRICE;
  4.  
[CST.CST_QTY]-Sum(SW_SLS.SWS_QTY) AS SumOfSWS_QTY
May 1 '07 #9
Thanks!

After some tinkering that worked. I had to pick a different name for the field as SumOfSWS_QTY was used earlier but i have it working now.

Once again thanks that was really helpful!
May 2 '07 #10
Denburt
1,356 Expert 1GB
Good deal glad I could help.
May 2 '07 #11

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

Similar topics

6
by: Jegger | last post by:
Hello! We have following situation; network with 100 users, aplication developed in Access, user DB deployed on SQL Server. Is it better to create query inside aplication (with code) and then...
4
by: August1 | last post by:
I've written an interface and implementation file along with a client source file that allows the use of an overloaded subtraction operator. However, when using the program, I'm running into a...
29
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them...
25
by: cory | last post by:
Hi, I have an Access database and am having an ASP.NEt application written for it. It is almost complete. I have a hosting company that I signed up with a month ago but before I did anything I...
11
by: maryjones11289 | last post by:
Hi, I have an app (lost the source code) that performs many different queries in order to achieve the results I'm looking for. Re-developing the app isn't really a big issue...but what would be...
10
by: Hank | last post by:
We have just recently migrated the data from our Access 2000 backend to Postgres. All forms and reports seem to run correctly but, in many cases, very slowly. We do not want to switch over until...
20
by: junky_fellow | last post by:
Hi, In my previous post I asked if sizeof may be implemented as a function. Somebody pointed a link that says that sizeof may calculated as follows with a warning that it is not guaranteed to...
5
by: jonceramic | last post by:
Hi All, I started developing in Access, and people took notice and so we're starting to migrate into our corporate's bigger Oracle system. I'll still be using my developed Access front ends,...
5
by: Keflavich | last post by:
Hey, I have a bit of code that died on a domain error when doing an arcsin, and apparently it's because floating point subtraction is having problems. I know about the impossibility of storing...
3
by: Bret Kuhns | last post by:
I recently started a co-op/internship at a company and they are looking to migrate a large legacy supported application from OLEDB to SQL Server. I'm doing prelim work in experimenting with the...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.