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

Problem with getting values using Query

manoj9849967222
Hi All

I have a great problem.
I have three tables one is "SALES" other one is "Purchase" & "Productid"

Now i want to get the closing stock out of it.

Say productid is 1.2 --------- Purchased---100 qty & Sales-----50 qty
1.3----------Purcahsed---300 qty & sales-----100 qty
1.2--------- Purcahsed--000 qty & sales-----20 qty

closing stock

Productid Closing stock
1.2--------------------30 qty
1.3-------------------200 qty


I am trying to get the closing stock using a simple query. but the values i am getting is wrong.


I need to do this on a urgent basis.


Please Help

Regards
Manoj.
Sep 28 '07 #1
6 1524
mlcampeau
296 Expert 100+
You could try something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT [ProductID.ProductID], (Sum([Purchase.QtyPurchased])-Sum([Sales.QtySold])) AS ClosingStock 
  2. FROM [your 3 tables]
If it doesn't work, please explain how it's not working, and let us know what you have tried.
Sep 28 '07 #2
HI

I have used these codes

SELECT productid.Productid, (Sum([Purchase.Qty])-Sum([Sales.Qty])) AS ClosingStock
FROM product, sales, purchase;

when i run this query it ask me to enter the productid & gives me a wrong figure
I dont know from where i am getting that figure.

or other wise i was think to get the closing stock using a query which would give me the total qty sold & total qty purchased productid wise.

and in report creat a textbox & write a formula Qtypurchased-qtysold.

but when i do this also i am getting wrong values.

Regards
Manoj
Sep 28 '07 #3
mlcampeau
296 Expert 100+
HI

I have used these codes

SELECT productid.Productid, (Sum([Purchase.Qty])-Sum([Sales.Qty])) AS ClosingStock
FROM product, sales, purchase;

when i run this query it ask me to enter the productid & gives me a wrong figure
I dont know from where i am getting that figure.

or other wise i was think to get the closing stock using a query which would give me the total qty sold & total qty purchased productid wise.

and in report creat a textbox & write a formula Qtypurchased-qtysold.

but when i do this also i am getting wrong values.

Regards
Manoj
Well, if it is asking you to enter the ProductId, then you must not have it named correctly in your query. Try going to the Query Design view and select productid from the drop down field list. Also, in your From clause, your tables are not joined at all. In your query design view, make sure that the tables are joined by productid.
Sep 28 '07 #4
mlcampeau
296 Expert 100+
Okay so I just did a test and this is how I had to get it to work. I made 3 queries.
The first sums the PurchasedQty:
Expand|Select|Wrap|Line Numbers
  1. SELECT Product.ProductID, Sum(Purchased.PurchasedQty) AS SumOfPurchasedQty
  2. FROM Product LEFT JOIN Purchased ON Product.ProductID = Purchased.ProductID
  3. GROUP BY Product.ProductID;
The second sums the SalesQty:
Expand|Select|Wrap|Line Numbers
  1. SELECT Product.ProductID, Sum(Sales.SalesQty) AS SumOfSalesQty
  2. FROM Product LEFT JOIN Sales ON Product.ProductID = Sales.ProductID
  3. GROUP BY Product.ProductID;
And the third gives the results you want:
Expand|Select|Wrap|Line Numbers
  1. SELECT Product.ProductID, SumPurchased.SumOfPurchasedQty-SumSales.SumOfSalesQty AS ClosingStock
  2. FROM (Product INNER JOIN SumSales ON Product.ProductID = SumSales.ProductID) INNER JOIN SumPurchased ON Product.ProductID = SumPurchased.ProductID;
Sep 28 '07 #5
Thanks for all your help.

I used the second option & it worked out


Thanks Again.

Regards
Manoj
Sep 28 '07 #6
mlcampeau
296 Expert 100+
Your welcome. I'm glad it worked for you.
Sep 28 '07 #7

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

Similar topics

4
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
5
by: vtreddy | last post by:
Hi All: In my application I am sending the input values through query string from a datagrid template column,I used URLEncode to encode the URL String, please find the input below, I am facing a...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
1
by: Eustice Scrubb | last post by:
I'm trying to use the Insert.aspx Quickstart and I'm getting a NULL pointer exception. Any help? <code> <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub...
3
by: pbali | last post by:
Hi, I am using PHP 5.1 and MySQL. I have a result set obtained by executing PDO:: query. I want to create an XML file by using this result set. The XML file will contain column names as XML node...
12
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
4
by: Kev | last post by:
Hello, I have an Access 2003 database running on an XP network. I have a datasheet subform containing a 28 day roster - shift1 to shift28. Each record has 1 RosterEmpID, 1 EmployeeNumber, 28...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.