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

select query problem

I have Two Tables

Tabel 1 is
Purchase

prodcode
billno
billdate
quantity

Tabel 2 is

Stock
prodcode
quantity

I m looking for the number of rows from purchase table which matches stock table with prodcode and quantity selected from purchases is less than or equal to quantity from stock table
e.g.

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

then the result should be
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 10
prod2 1003 11/3/2007 200

Thanks and Regds
Narendra
Sep 19 '07 #1
6 1376
azimmer
200 Expert 100+
I have Two Tables

Tabel 1 is
Purchase

prodcode
billno
billdate
quantity

Tabel 2 is

Stock
prodcode
quantity

I m looking for the number of rows from purchase table which matches stock table with prodcode and quantity selected from purchases is less than or equal to quantity from stock table
e.g.

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

then the result should be
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 10
prod2 1003 11/3/2007 200

Thanks and Regds
Narendra
Although I don't quite understand your example (it seems that for billno=1004 there's enough stock and still missing from the result table) but anyway join the tables with more than one condition like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT p.code, p.billno, p.billdate, p.qty
  2. FROM purchase p INNER JOIN stock s ON p.code=s.code AND p.qty<=s.quantity
  3.  
Sep 19 '07 #2
Although I don't quite understand your example (it seems that for billno=1004 there's enough stock and still missing from the result table) but anyway join the tables with more than one condition like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT p.code, p.billno, p.billdate, p.qty
  2. FROM purchase p INNER JOIN stock s ON p.code=s.code AND p.qty<=s.quantity
  3.  
I m sorry the result should be

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

then the result should be
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 10
prod2 1003 11/3/2007 100
prod2 1004 11/3/2007 100

In short I would like to list all the last purchases corresponding to the stock lying with us.


Thanks and Regds
Narendra
Sep 19 '07 #3
azimmer
200 Expert 100+
I m sorry the result should be

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

then the result should be
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 10
prod2 1003 11/3/2007 100
prod2 1004 11/3/2007 100

In short I would like to list all the last purchases corresponding to the stock lying with us.


Thanks and Regds
Narendra
Sorry, Narendra, it's still not quite clear.
1001: OK, purchase 120, stock 130
1002: if purchase is 100, stock is 130, a result of 10 implies that you're looking for the 130 stock - 120 (stock used up by 1001) = 10 left as the result; or the result 10 is a typo (should be 100)
1003:purchase=200, stock=200, why isn't the result 200? Or is purchase a typo and should be 100.
1004:can be OK if 1002 & 1003 are clarified

Can you, please, clarify it?
Sep 19 '07 #4
Sorry, Narendra, it's still not quite clear.
1001: OK, purchase 120, stock 130
1002: if purchase is 100, stock is 130, a result of 10 implies that you're looking for the 130 stock - 120 (stock used up by 1001) = 10 left as the result; or the result 10 is a typo (should be 100)
1003:purchase=200, stock=200, why isn't the result 200? Or is purchase a typo and should be 100.
1004:can be OK if 1002 & 1003 are clarified

Can you, please, clarify it?
Hi again to simplify
purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

pl note
I would like to list all the last purchases corresponding to the stock lying with us i.e. by FIFO method.

then the result should be
code billno date purchase qty bal. qty
prod1 1001 01/01/2007 120 30
prod1 1002 10/2/2007 100 100
prod2 1003 11/3/2007 200 100
prod2 1004 11/3/2007 100 100




Thanks and Regds
Narendra
Sep 19 '07 #5
I have Two Tables

Tabel 1 is
Purchase

code
billno
billdate
quantity

Tabel 2 is
Stock

code
quantity

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

pl note
I would like to list all the last purchases corresponding to the stock lying with us i.e. by FIFO method.

then the result should be
code billno date purqty balance
prod1 1001 01/01/2007 120 30
prod1 1002 10/2/2007 100 100
prod2 1003 11/3/2007 200 100
prod2 1004 11/3/2007 100 100

Thanks and Regds
Narendra
Sep 19 '07 #6
azimmer
200 Expert 100+
I have Two Tables

Tabel 1 is
Purchase

code
billno
billdate
quantity

Tabel 2 is
Stock

code
quantity

purchase
code billno billdate qty
prod1 1001 01/01/2007 120
prod1 1002 10/2/2007 100
prod2 1003 11/3/2007 200
prod2 1004 12/4/2007 100

stock
code quantity
prod1 130
prod2 200

pl note
I would like to list all the last purchases corresponding to the stock lying with us i.e. by FIFO method.

then the result should be
code billno date purqty balance
prod1 1001 01/01/2007 120 30
prod1 1002 10/2/2007 100 100
prod2 1003 11/3/2007 200 100
prod2 1004 11/3/2007 100 100

Thanks and Regds
Narendra
Sorry, I still don't get it, maybe I'm impossible. I make one last attempt to get a grasp on it; if I still cannot I'll admit to be too dumb and let others have a go. So let's go step by step:

At 01/01/2007 (before the first transaction) stocks are: prod1=130, prod2=200. I assume that stocks do not grow during transactions (purchases).

Transaction: prod1 1001 01/01/2007 120
It should get listed because 120<130, with an after-transaction balance of prod1=10.
According to your results it gets listed with a balance of 30. Where does this balance come from?

Transaction: prod1 1002 10/2/2007 100
Does it get listed? Note, that 100>10 (10=balance), so it cannot be fulfilled.
According to your results it gets listed with a balance of 100. Where does this balance come from?

Transaction: prod2 1003 11/3/2007 200
It should get listed because 200=200, with an after-transaction balance of prod2=0.
According to your results it gets listed with a balance of 100. Where does this balance come from?

Transaction: prod2 1004 12/4/2007 100
Does it get listed? Note, that 100>0 (0=balance), so it cannot be fulfilled.
According to your results it gets listed with a balance of 100. Where does this balance come from? Also, I believe that the date listed is copied and not modified (should be 12/04/2007).
Sep 19 '07 #7

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

Similar topics

3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: VMB | last post by:
Using version: 4.0.18-Max-log We're getting some fairly poor performance when doing an INSERT INTO temp_table ... SELECT (...). The SELECT is grabbing 2K row chunks from its table, so the...
12
by: bokke | last post by:
Hi, I have a page with a link <a href="Contributor.php?action=&SubCat=<?php echo $row; ?>"><?php echo $row;?></a> that does to a page with a SELECT $query = "SELECT * FROM news WHERE...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
4
by: The.Daryl.Lu | last post by:
Hi, Have a bit of a problem... I've created a form in Access and will use the form for a user to query a table based on the selected fields. The problem lies in that I was using checkboxes for...
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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.