I have the following code: -
SELECT MAX(INVENTORY_TRANSACTION_HIST.DATE_APPLIED) AS LAST_TRANS, INVENTORY_TRANSACTION_HIST.PART_NO
-
-
FROM INVENTORY_TRANSACTION_HIST INNER JOIN
-
INVENTORY_PART_IN_STOCK ON INVENTORY_TRANSACTION_HIST.PART_NO = INVENTORY_PART_IN_STOCK.PART_NO
-
-
WHERE (INVENTORY_TRANSACTION_HIST.TRANSACTION_CODE IN ('PICK-IN', 'PICK-OUT', 'NREC', 'ARRIVAL')) AND
-
(INVENTORY_TRANSACTION_HIST.CONTRACT = :site) AND (INVENTORY_PART_IN_STOCK.QTY_ONHAND > 0) AND
-
(INVENTORY_TRANSACTION_HIST.DIRECTION <> '0')
-
-
GROUP BY INVENTORY_TRANSACTION_HIST.PART_NO
The report works fine but, when a record identified with max date applied has a trasaction code not included in the code, the report drops it. I was hoping it would select the next applicable max date applied according to my transaction code criteria. So my question is, how can I get SQL to grab the next 'max date applied' based on the transaction codes identified in the code.
1 1774 pbmods 5,821
Recognized Expert Expert
Heya, abetancur. Welcome to TSDN!
Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Try adding to the WHERE clause: -
SELECT
-
MAX(`INVENTORY_TRANSACTION_HIST`.`DATE_APPLIED`)
-
AS `LAST_TRANS`,
-
`INVENTORY_TRANSACTION_HIST`.`PART_NO`
-
FROM
-
(
-
`INVENTORY_TRANSACTION_HIST`
-
INNER JOIN
-
`INVENTORY_PART_IN_STOCK`
-
ON `INVENTORY_TRANSACTION_HIST`.`PART_NO` = `INVENTORY_PART_IN_STOCK`.`PART_NO`
-
)
-
WHERE
-
(
-
`INVENTORY_TRANSACTION_HIST`.`TRANSACTION_CODE`
-
IN
-
(
-
'ARRIVAL'
-
'NREC',
-
'PICK-IN',
-
'PICK-OUT',
-
)
-
AND
-
`INVENTORY_TRANSACTION_HIST`.`CONTRACT` = :site
-
AND
-
`INVENTORY_PART_IN_STOCK`.`QTY_ONHAND` > 0
-
AND
-
`INVENTORY_TRANSACTION_HIST`.`DIRECTION` <> '0'
-
AND -- ADD THIS:
-
`INVENTORY_TRANSACTION_HIST`.`DATE_APPLIED` < '{last value}'
-
)
-
GROUP BY
-
`INVENTORY_TRANSACTION_HIST`.`PART_NO`
-
Note also that when listing values for an 'IN' subclause, you should put them in alphabetical order so that MySQL doesn't have to sort them (MySQL uses a binary search on IN subclauses).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: androtech |
last post by:
Hello,
I'm looking for a function that returns a date range for a specified week
number of the year.
I'm not able to find functions like this anywhere. Any pointers/help would
be much appreciated.
TIA
|
by: Gord |
last post by:
Many scripts and calendars call client side system time in order to
make presentations.
However, the client's time may be improperly set, if set at all,
and/or the relevant time may be from another time zone.
It would be of great value if the time of some central source could be
drawn, in the form of a ".js" file, into the script to avoid
dependence on the client's date/time.
|
by: Tony |
last post by:
Hey guys,
I use Google Groups quite a bit as it is an enormous wealth of
information, and now I need some help. I have created a query using
parameters to capture a range of date, the date is also formatted.
test: Format(,"mm/dd/yy")
Between And
|
by: John Wildes |
last post by:
Hello all
I'm going to try and be brief with my question, please tell me if I have the
wrong group.
We are querying transaction data from a DB3 database application. The dates
are stored as text fields. Each date for example 10/31/03 or October 31st
2003 is stored as 10/31/A3 in the system. My reasoning for this is because
they couldn't solve their Y2K problem or this is their solution to it. All
dates prior to 2000 are stored...
|
by: Khurram |
last post by:
I have a problem while inserting time value in the datetime Field.
I want to Insert only time value in this format (08:15:39) into the SQL
Date time Field.
I tried to many ways, I can extract the value in timeonly format by using
this command
Format(now,"HH:mm:ss")
But when I insert it into the Sql Server database, it embadded date value
with it.
the output looks like that "01/01/1900 08:59:00" in that case time is
| |
by: Tom |
last post by:
I need to modify the default behavior of Date.ToString() on all pages
of my ASP.Net (2.0) site. I don't need to localize my app (it's an
intranet-only site), but I need to enforce a specific date/time format
sitewide ("MM/dd/yyyy HH:mm:ss") and I don't want to have to write that
each time I have to format a date to string.
I googled CurrentCulture and Date Format, and I found some articles on
customizing the default culture of your...
|
by: Paul Brady |
last post by:
In a self-contained database, the following query works fine and
returns courses taken on 3/8/2000:
----------
SELECT TransactionCourses.CourseID, TransactionCourses.MbrID,
TransactionCourses.CourseDate
FROM TransactionCourses
WHERE (((TransactionCourses.CourseID)=1103) AND
((TransactionCourses.CourseDate)=#3/8/2000#))
ORDER BY TransactionCourses.MbrID, TransactionCourses.CourseDate;
---------------
|
by: bml337 via AccessMonster.com |
last post by:
I need to create a supervisory log for my clients. The log table has the
following fields date, checkbox and notes. now for the tricky part... one
log is weekly and should be generated every monday. i have a similar log
that will be run on the first of each month.
so i need a record auto generated every Monday of the week and another
generated on the first of every month... these will be in two separate tables.
.. also possible to...
|
by: Strasser |
last post by:
How much did a collection of items cost at some date in the past?
If anyone could help me with this, I would be most appreciative.
I am learning VBA in Excel, but haven’t yet learned VBA for Access.
I have a recipe database.
Database tracks recipes, ingredients and the cost of ingredients.
Number of ounces of ingredients per recipe remains constant.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |