473,399 Members | 2,146 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,399 software developers and data experts.

SQL Query Help :)

Ok I think this is a tough one. I have two tables: an Inventory table and an Inventory History table. The Inventory table has the current Quantity of each Product. The Inventory History table has the Quantity of each Product whenever it changed, along with the Date when it changed.

I'm trying to create a query that takes a date from the user as a parameter and gives the Quantity of each Product on that day from the Inventory History table. If there is no record for that day, then it gives the most recent one before the inputted date.

The net effect is that the query gives the actual inventory count of each product on the day the user specifies.

Is this hard? :(
Oct 18 '10 #1

✓ answered by nico5038

No, just use a WHERE clause to check for the max datefield less or equal the entered value like:
Expand|Select|Wrap|Line Numbers
  1. WHERE DateField = Dmax("datefield","tblYours","Datefield <=#" & [Datefield] & "#")
  2.  
Getting the idea ?

Nic;o)

2 1042
nico5038
3,080 Expert 2GB
No, just use a WHERE clause to check for the max datefield less or equal the entered value like:
Expand|Select|Wrap|Line Numbers
  1. WHERE DateField = Dmax("datefield","tblYours","Datefield <=#" & [Datefield] & "#")
  2.  
Getting the idea ?

Nic;o)
Oct 18 '10 #2
nico5038
3,080 Expert 2GB
One additional remark, when you have multiple stocks on the same date, then multiple rows can be returned.
To overcome that add a SORT BY on a field that's relevant and use SELECT TOP 1 to get just one. It's an exception, but just in case.

Nic;o)
Oct 18 '10 #3

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

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
7
by: Mike Watson | last post by:
Hello, I created a table with only two columns "Month" and "FY". The table has only one row. The purpose is to change two cells content: - once a month ("Month") and - once a year ("FY")......
3
by: osman7king | last post by:
If I want to generate dynamically some queries in a php 5 application to retrieve information from an postgresql database. is there a maximum length for this query? When i use the IN statement,...
1
by: NareshN | last post by:
Hi I have 4 weeks data of employees.Based on matchingOff column i need to find no of employee who are getting weekOff on sameday for all 4weeks.Suppose emp 101 is getting weekOff on...
1
by: osman7king | last post by:
If I want to generate dynamically some queries in a php 5 application to retrieve information from an Oracle database. is there a maximum length for this query? When i use the IN statement, how...
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: 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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
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,...
0
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...

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.