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

sql quest



tbl1.....
fPum
p1
p2
p3
========================
tbl2.......
fNum fDate fGoods fIn fOut fStock
1 5/6 p1 9 1 8
2 5/7 p2 7 3 4
3 5/7 p1 10 0 18
4 5/8 p3 10 9 1
5 5/10 p3 4 3 2

then,
search due : 5/8 ~ 5/11
and then, the result is below
i want to make query to below result.

fDate fGoods fIn fOut fStock
5/8 p1 0 0 18
5/8 p2 0 0 4
5/8 p3 10 9 1
5/9 p1 0 0 18
5/9 p2 0 0 4
5/9 p3 10 9 1
5/10 p1 0 0 18
5/10 p2 0 0 4
5/10 p3 4 3 2


*** Sent via Developersdex http://www.developersdex.com ***
Jul 4 '06 #1
1 1481
x taol wrote:
tbl1.....
fPum
p1
p2
p3
========================
tbl2.......
fNum fDate fGoods fIn fOut fStock
1 5/6 p1 9 1 8
2 5/7 p2 7 3 4
3 5/7 p1 10 0 18
4 5/8 p3 10 9 1
5 5/10 p3 4 3 2

then,
search due : 5/8 ~ 5/11
and then, the result is below
i want to make query to below result.

fDate fGoods fIn fOut fStock
5/8 p1 0 0 18
5/8 p2 0 0 4
5/8 p3 10 9 1
5/9 p1 0 0 18
5/9 p2 0 0 4
5/9 p3 10 9 1
5/10 p1 0 0 18
5/10 p2 0 0 4
5/10 p3 4 3 2


*** Sent via Developersdex http://www.developersdex.com ***
tbl1
ID1 AutoNumber
fPum Text
ID1 fPum
1 p1
2 p2
3 p3

tbl2
ID2 AutoNumber
fNum Long
fDate Date/Time Format: m/d
fGoods Text
fIn Long
fOut Long
fStock Long

qryFirst:
SELECT fDate, fPum AS fGoods FROM tbl1, tbl2 WHERE fDate BETWEEN #5/8#
AND #5/11# ORDER BY fDate, fPum;

!qryFirst
fDate fGoods
5/8 p1
5/8 p2
5/8 p3
5/10 p1
5/10 p2
5/10 p3

qrySecond:
SELECT qryFirst.fDate, qryFirst.fGoods, Nz((SELECT SUM(A.fIn) FROM tbl2
AS A WHERE A.fDate = qryFirst.fDate And A.fGoods = qryFirst.fGoods), 0)
As fIn, Nz((SELECT SUM(A.fOut) FROM tbl2 AS A WHERE A.fDate =
qryFirst.fDate And A.fGoods = qryFirst.fGoods), 0) As fOut, Nz((SELECT
SUM(A.fIn) FROM tbl2 AS A WHERE A.fDate <= qryFirst.fDate And A.fGoods
= qryFirst.fGoods), 0) - Nz((SELECT SUM(A.fOut) FROM tbl2 AS A WHERE
A.fDate <= qryFirst.fDate And A.fGoods = qryFirst.fGoods), 0) AS fStock
FROM qryFirst;

!qrySecond:
fDate fGoods fIn fOut fStock
5/8 p1 0 0 18
5/8 p2 0 0 4
5/8 p3 10 9 1
5/10 p1 0 0 18
5/10 p2 0 0 4
5/10 p3 4 3 2

The problem with this is that the missing dates are, well, missing.
Maybe this will help get you started on your quest. Let me know if you
need the missing dates for certain or if these queries are incorrect.
Note: Most people in this newsgroup would argue against storing fStock
in tbl2 at all since it can be calculated.

James A. Fortune
CD********@FortuneJames.com

Jul 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Trent | last post by:
Hello, I was wondering if anyone here could help with a Quest Central issue. I have two different hosts listed in Quest Central. Each host has a database on it, but the databases have the...
3
by: Robert Stearns | last post by:
Apparently due to an intellectual property suit by CA, Quest Central for DB2 has gone away. They can/will not sell any license extensions. In a project I am doing, we make extensive use of quest...
1
by: lewi | last post by:
How do I access data members of a parent form class and from a function of a child form class. Both classes are both in the same name space and are public classes... The child form is a Modal...
4
by: bj7lewis | last post by:
I am currently C++/Win32/MFC & C# programmer using VS.NET 2002 and jumped into VS.NET 2003 but that was a waste so I skipped VS.NET 2005 cause buying VS.NET 2003. Now after checking out VS.NET 2008...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.