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

Max of one field only if another field has a certain value

Hi, what a great resource this forum is! Hopefully you all can help:

I have one field called "OPERATION_NO" another called "WORK_CENTER_NO" and another field called "OPER_STATUS_CODE"
I'm using "2110" as the criteria for "WORK_CENTER_NO"

What I want is to create another field called "CURRENT_WC" where the value will be the "WORK_CENTER_NO" of the highest "OPERATION_NO" that has an "OPER_STATUS_CODE" of "Closed"

I'm going crazy trying to figure this out so hopefully someone a lot smarter than me can help
Aug 28 '07 #1
8 2871
JKing
1,206 Expert 1GB
Hi, what a great resource this forum is! Hopefully you all can help:

I have one field called "OPERATION_NO" another called "WORK_CENTER_NO" and another field called "OPER_STATUS_CODE"
I'm using "2110" as the criteria for "WORK_CENTER_NO"

What I want is to create another field called "CURRENT_WC" where the value will be the "WORK_CENTER_NO" of the highest "OPERATION_NO" that has an "OPER_STATUS_CODE" of "Closed"

I'm going crazy trying to figure this out so hopefully someone a lot smarter than me can help
Are you looking for a query?
Something like this would return the work_center_no that has the highest operation_no and oper_status_code of closed

Expand|Select|Wrap|Line Numbers
  1. SELECT Work_center_No
  2. FROM tblYourTable
  3. WHERE operation_no = (SELECT MAX(operation_No) from tblYourTable WHERE oper_status_code = 'closed')
  4.  
Aug 28 '07 #2
Are you looking for a query?
Something like this would return the work_center_no that has the highest operation_no and oper_status_code of closed

Expand|Select|Wrap|Line Numbers
  1. SELECT Work_center_No
  2. FROM tblYourTable
  3. WHERE operation_no = (SELECT MAX(operation_No) from tblYourTable WHERE oper_status_code = 'closed')
  4.  
I'd like to return the work_center_no (that you provided above) in its own field called "CURRENT_WC" but I want to return this where there is a work_center_no 2110 and oper_status_code <>"Closed" which I already have in the Critera field. Does that make sense?
Aug 28 '07 #3
JKing
1,206 Expert 1GB
I'm a little confused.

You want to always show the work_center_no for the highest operation along with the record information where the work_center_no = 2110?

Now you said oper_status_code should be 'closed' in your first post and now you've shown it <> 'closed'?

Is this the kind of output you are looking for?
Expand|Select|Wrap|Line Numbers
  1. work_center_no     operation_no     oper_status_code     wc_current
  2. 2110                   10                open               3456
  3.  
Aug 28 '07 #4
Yes, that is exactly what I am looking for, where wc current is a closed operation. Sorry for the confusion.
Aug 28 '07 #5
JKing
1,206 Expert 1GB
Make two queries. The first being the sql that I posted returning the value of the current_WC.

Base your second query off your table and the previously made query. Select the fields from the table you and then the work_center_no from the previous query and alias it as whatever you want.

Say you saved the first query as qselCurrent_WC your query might look something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblYourTable.work_center_no, operation_no, oper_status_code, qselCurrent_WC.work_center_no AS Current_WC
  2. FROM tblYourTable, qselCurrent_WC
  3. WHERE tblYourTable.work_center_no = 2110
  4.  
Aug 28 '07 #6
Sorry, I'm new to this. I know I'm close but I'm getting the following error message:

"The specified 'WORK_CENTER_NO' could refer to more than one table listed in the FROM clause of your SQL statement."

Here is the code from the first query:
Expand|Select|Wrap|Line Numbers
  1. SELECT IFSAPP_SHOP_ORDER_OPERATION.WORK_CENTER_NO
  2. FROM IFSAPP_SHOP_ORDER_OPERATION
  3. WHERE (((IFSAPP_SHOP_ORDER_OPERATION.OPERATION_NO)=(SELECT MAX(OPERATION_NO) FROM IFSAPP_SHOP_ORDER_OPERATION WHERE OPER_STATUS_CODE = 'Closed')));
  4.  
Here is the code from the second query:
Expand|Select|Wrap|Line Numbers
  1. SELECT IFSAPP_SHOP_ORDER_OPERATION.ORDER_NO, WORK_CENTER_NO, OPERATION_NO, OPER_STATUS_CODE, qselCurrent_WC.WORK_CENTER_NO AS Current_WC
  2. FROM IFSAPP_SHOP_ORDER_OPERATION, qselCurrent_WC
  3. WHERE IFSAPP_SHOP_ORDER_OPERATION.WORK_CENTER_NO = 2110
  4.  
Aug 28 '07 #7
JKing
1,206 Expert 1GB
You need to reference the table name before the work_center_no field in the SELECT line of your query.
Aug 28 '07 #8
I think I got that part figured out. Now when I run the second query it gives me the same Current_WC for every ORDER_NO. I think the first query is returning the max of all operations across all orders, I just want the max operation for each order no. Can I impose on you once more?
Aug 28 '07 #9

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
2
by: Rooksarii | last post by:
Hello folks, Let me first apologize for any impropper terminology I may use as I am presently trying to broaden my Office knowledge by diving into Access head on. My specific problem is this....
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
13
by: - Kees van der Bent - | last post by:
/* With the following: */ typedef struct { unsigned char a : 1; unsigned char b : 1; } sss_t; sss_t sss; unsigned char ppp; main()
4
by: abCSharp | last post by:
I understand that static variables have app-domain scope. Till the app-domain is in memory, the static variable will be in memory. When are the app-domains unloaded is the question. I have read...
2
by: Rodusa | last post by:
I have a hidden field inside one datagrid which I can't get to make it keep its state after a postback event. Look field: <input type="hidden" id="TxtHiddenItem_id" name="TxtHiddenItem_id"...
7
by: turtle | last post by:
I want to find out the max value of a field on a report if the field is not hidden. I have formatting on the report and if the field doesn't meet a certain criteria then it is hidden. I want to...
2
by: Coll | last post by:
I have a field that I would like to display on a report only if the value of another field matches a certain criteria. If it does match I need the label & the field value to display (though I'm...
3
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in...
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
marktang
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,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.