473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1497
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********@Fort uneJames.com

Jul 4 '06 #2

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

Similar topics

1
2408
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 *same* name. I can add the database to the first host OK. But when I try to add the second host's database, I get an error saying "Database name already exists." Is there a way around this problem? Why does it matter if databases
3
1727
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 due to its ease of use and speed. If you know of a product with similar capabilities, please let me know. My license is running out this month. Inexpensive is very important since we're a dining room table startup.
1
1950
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 dialog and should setup some of these data members and validate them before OK button handler lets the dialog be dismissed by this dlg closing prevention code... //access and validate data members...
4
1556
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 Beta2 I think VS.NET 2008 is worth the upgrade. But I want to hold off(five+ years depending on features) on more further upgrades OSs & ISEs cause of too many releases - too soon - too much money.... So now going to VS.NET 2008 I want to setup a...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10103
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...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
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
8934
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...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.