find the record with the maxvalue
From: ccliu <ccliu_at_csie.nctu.edu.tw>
Date: 1996/11/14
Message-ID: <56e0ds$m21_at_netnews.csie.nctu.edu.tw>#1/1
Date: 1996/11/14
Message-ID: <56e0ds$m21_at_netnews.csie.nctu.edu.tw>#1/1
Hi,
I have a procedure that will search for a table and find the max value of a column, then get the record that has this max value. Because this table is huge, from above, I have to search twice. Is there any other method That I can only serach once and get the record? The table LotJob in the following SPL is the huge table.
CAn you give me some advice?? Thanks.
Jack
>>>>>>>>>>>>> SPL codes 1 >>>>>>>>>>
CREATE PROCEDURE lott02a(
,i_Lot CHAR(16) -- Lot
) RETURNING
,INTEGER -- Instance
,CHAR(16) -- Lot
,CHAR(16) -- Product
,CHAR(16) -- Process
,CHAR(16) -- Route
,CHAR(32) -- RouteName
; DEFINE o_Instance INTEGER; DEFINE o_Lot CHAR(16); DEFINE o_Product CHAR(16); DEFINE o_Process CHAR(16); DEFINE o_Route CHAR(16); DEFINE o_RouteName CHAR(32); DEFINE w_Process CHAR(16); DEFINE w_LotJobSequence INTEGER; DEFINE ErrorNumber INTEGER; DEFINE ErrorSQL INTEGER; DEFINE ErrorISAM INTEGER; DEFINE ErrorObject CHAR(40); LET o_Instance = 0; FOREACH SELECT Lot ,Product ,Process INTO o_Lot ,o_Product ,w_Process FROM Lot WHERE Lot LIKE i_Lot SELECT MAX(LotJobSequence) INTO w_LotJobSequence FROM LotJob WHERE Lot = o_Lot; IF w_LotJobSequence IS NULL THEN LET o_Process = w_Process; LET o_Route = NULL; LET o_RouteName = NULL; ELSE SELECT Process ,Route INTO o_Process ,o_Route FROM LotJob WHERE LotJob.Lot = o_Lot AND LotJob.LotJobSequence = w_LotJobSequence; SELECT RouteName INTO o_RouteName FROM Route WHERE Route = o_Route; END IF LET o_Instance = o_Instance + 1; RETURN o_Instance ,o_Lot ,o_Product ,o_Process ,o_Route ,o_RouteName WITH RESUME; END FOREACH
END PROCEDURE; >>>>>>>>>>>>>> SPC code 2 >>>>>>>>>>>>>>>
CREATE PROCEDURE "sdi".lott02a(
,i_Lot CHAR(16) -- Lot
) RETURNING
,INTEGER -- Instance
,CHAR(16) -- Lot
,CHAR(16) -- Product
,CHAR(16) -- Process
,CHAR(16) -- Route
,CHAR(32) -- RouteName
; DEFINE o_Instance INTEGER; DEFINE o_Lot CHAR(16); DEFINE o_Product CHAR(16); DEFINE o_Process CHAR(16); DEFINE o_Route CHAR(16); DEFINE o_RouteName CHAR(32); DEFINE w_CurrentQuantity INTEGER; DEFINE w_Process CHAR(16); DEFINE w_LotJobSequence INTEGER; LET o_Instance = 0; LET w_LotJobSequence = NULL; FOREACH SELECT Lot ,Product ,Process INTO o_Lot ,o_Product ,w_Process FROM Lot WHERE Lot LIKE i_Lot
- The following is the different part
FOREACH SELECT Process ,Route ,Step ,LotJobSequence INTO o_Process ,o_Route ,o_Step ,w_LotJobSequence FROM LotJob WHERE Lot = o_Lot ORDER BY LotJobSequence EXIT FOREACH; END FOREACH;
IF w_LotJobSequence IS NULL THEN LET o_Process = w_Process; LET o_Route = NULL; LET o_RouteName = NULL; LET o_Step = NULL; LET o_StepName = NULL; ELSE SELECT RouteName INTO o_RouteName FROM Route WHERE Route = o_Route; SELECT StepName INTO o_StepName FROM Step WHERE Step = o_Step; END IF LET o_Instance = o_Instance + 1; RETURN ,o_Instance ,o_Lot ,o_Product ,o_Process ,o_Route ,o_RouteName WITH RESUME; END FOREACH
END PROCEDURE; Received on Thu Nov 14 1996 - 00:00:00 CET