473,657 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with getting values using Query

manoj9849967222
48 New Member
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 1538
mlcampeau
296 Recognized Expert Contributor
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
manoj9849967222
48 New Member
HI

I have used these codes

SELECT productid.Produ ctid, (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 Recognized Expert Contributor
HI

I have used these codes

SELECT productid.Produ ctid, (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 Recognized Expert Contributor
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
manoj9849967222
48 New Member
Thanks for all your help.

I used the second option & it worked out


Thanks Again.

Regards
Manoj
Sep 28 '07 #6
mlcampeau
296 Recognized Expert Contributor
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
2740
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 problem with the table set-up. I just can't find the problem. These are the fields in my table: Table1 ID (primary key) AutoNumber
13
4220
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 solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003 Developer Extensions. Initially I developed the database without planning on creating a runtime app...
5
2414
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 problem when the input string contains ® character , Here from ASP.NET I am redirecting to the ASP based system,when I give same input from ASP based system, it is showing Microsoft%AE%20Access%20 ,with this I am getting the correct results, where as...
7
2912
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 database into classes, which are used throughout the application. I have made class collections which, upon reading from the DB, create an instance of the class and store the DB values in there temporarily. My problem is that if user1 looks at...
1
1534
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 Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL Server myConnection = New SqlConnection("Data Source=SERVER;" _
3
2743
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 name and column values as node values. $orders = $db->query($sql); if (!empty($orders)) {
12
1694
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 the type of report to generate: Select the type of report to display: <form runat="server"> <asp:DropDownList AutoPostBack="true" ID="report" runat="server"> <asp:listitem>Report Type 1</asp:listitem>
29
5497
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 basically almost any change I make to how the query is executed (so that it still performs the same function) causes the performance to jump from a dismal 7 or 8 seconds to instantaneous. It's a very simple query of the form: SELECT Min(MyValue)...
4
2791
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 shift fields, and 1 shiftTotal field and 1 HoursTotal field. Datasheet may look like:
4
3575
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 order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in the...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.