MAX( ) function in 2 columns... Wrong Data
Hi Folks,
I have A DDIC Table with
mandt, Destination, Date, Time, KUNNR and some other columns.
Now I want to determine the LATEST entry for a KUNNR.
Now I did:
SELECT
mandt desti kunnr MAX( erdat )
MAX( ertim ) [..other nonkey fields.]
FROM MYTABLE INTO wa
WHERE desti = '10010'
AND kunnr = '0000000005'
AND not_checked = 'X'
GROUP BY mandt desti kunnr [..other nonkey fields.].
WRITE [ALL FIELDS]
ENDSELECT.
Now I get 5(!) results:
001 RE3_001 5 11.03.2009 12:59:55
001 RE3_001 5 12.03.2009 15:29:01
001 RE3_001 5 11.03.2009 19:27:50
001 RE3_001 5 11.03.2009 13:23:30
001 RE3_001 5 30.06.2008 16:45:26
what is that?
I only needed the 12.03.2009 at 15:29:01 .....
what do I do wrong?
what about the MAX() ?
THX
Markus Völker wrote:
> SELECT
> mandt desti kunnr MAX( erdat )
> MAX( ertim )
> FROM MYTABLE INTO wa
> WHERE desti = '10010'
> AND kunnr = '0000000005'
> AND not_checked = 'X'
> GROUP BY mandt desti kunnr .
>
> ENDSELECT.
> THX
Try something like this:
SELECT
desti kunnr
FROM MYTABLE as o INTO wa
WHERE desti = '10010'
AND kunnr = '0000000005'
AND not_checked = 'X'
AND ertim = ( select max(ertim)
from mytable as i
where o~desti = i~desti
and o~kunnr = i~kunnr )
ENDSELECT.
Maybe you have to adopt the select statement above to fit your needs a little bit.
Similar Messages
-
Max function for table having no rows
Hi All
I have a table in which initially no rows. I am running max() function for a column and then wnats to add 1.
But when no rows there below code in not working
select max(code) into p_maxCode from cms_codedetails where codetypeid=0;
p_maxCode:=p_maxCode+1;
dbms_output.PUT_LINE('p_maxCode: '||p_maxCode);
result is:
p_maxCode:
How can I handle the this to get 1 if no rows in the table .Hi !
Max function in yur case returns NULL and then
null + <anything> ... is still null
You can do
p_maxCode:=nvl(p_maxCode,0)+1;
or
select nvl(max(code),0) into p_maxCode from cms_codedetails where codetypeid=0;
Of course if YOU have decide that null in this case can be treated as 0
T -
Function sometimes return wrong data
Hi all.
I have a very strange problem with a function. Situation is this: I have an application that handles processes. Each process have a number of steps that is arranged in a matrix like layout. User clicks a step to start/execute it.
Now in a list of current processes i want to have an indication of how "far" a process has reached so i created a function for that and included that in my processlist fetch.
gchs_user_process_steps is the table where the user data for the process step is
gchs_process_steps is the definition table of what steps a process has
gchs_steps is the definition table of all steps
The below function is supposed to return latest step user clicked in the display matrix. tier is used to store the column number and sortorder is the row number of any step user clicked.
CREATE OR REPLACE FUNCTION FN_REACHEDSTEP(p_user_process_id NUMBER)
RETURN VARCHAR IS
ret VARCHAR(30);
ret_id INTEGER;
ret_num INTEGER;
BEGIN
ret := '';
ret_id := 0;
ret_num := 0;
BEGIN
SELECT substr(step_name,1,30),step_id,reached INTO ret,ret_id,ret_num
FROM (
SELECT a.*, rownum rnum
FROM (
SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
WHERE ups.gchs_process_step_id=ps.id AND
ps.gchs_step_id=s.id AND
ups.gchs_user_process_id=p_user_process_id
GROUP BY s.name,ps.id
ORDER BY 3 DESC) a
WHERE rownum <= 1 )
WHERE rnum >= 1;
EXCEPTION
WHEN OTHERS THEN
ret:='';
END;
RETURN ret;
EXCEPTION
WHEN OTHERS THEN
ret := '';
RETURN ret;
END FN_REACHEDSTEP;
Now the problem is that the function sometimes return wrong value. The name of the step that is returned is not the one i get if i run the SQL by itself.
So doing a
SELECT substr(step_name,1,30),step_id,reached INTO ret,ret_id,ret_num
FROM (
SELECT a.*, rownum rnum
FROM (
SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
WHERE ups.gchs_process_step_id=ps.id AND
ps.gchs_step_id=s.id AND
ups.gchs_user_process_id=21680
GROUP BY s.name,ps.id
ORDER BY 3 DESC) a
WHERE rownum <= 1 )
WHERE rnum >= 1;
and a
select fn_ReachedStep(21680) from dual;
will sometimes return different values.
So is the function fundamentally wrong or is there any cache or something that i've missed that could hold "old" function outputs or am i missing something else.
Thankful for any clues.
I'm using Oracle 10.2.0.1.0
Best regards
/Tomas
Edit: Here's some data that the system uses.
gchs_steps
ID NAME
10000 Step 1
10020 Step 2
10021 Step 3
10022 Step 4
10023 Step 5
10060 Step 6
10140 Step 7
gchs_process_steps
ID GCHS_STEP_ID TIER SORTORDER
10000 10000 0 1
10001 10020 1 1
10002 10021 1 2
10003 10022 2 1
10020 10023 3 5
10060 10060 3 4
10080 10140 3 2
10040 10040 3 3
10100 10160 4 3
10160 10220 4 2
11640 11640 3 1
11660 11660 0 6
11661 11661 0 7
11600 11600 0 4
11620 11620 4 1
gchs_user_process_steps
ID GCHS_USER_PROCESS_ID GCHS_PROCESS_STEP_ID
35541 21680 10002
38441 21680 10020
38440 21680 10000
52062 21680 10060
Relations beween table is
gchs_user_process_steps.gchs_process_step_id=gchs_process_steps.id
and
gchs_process_steps.gchs_step_id=gchs_steps.id
So doing the SQL alone will always return
SUBSTR(..) STEP_ID REACHED
Step 5 10020 3005
but executing the function sometimes returns
FN_REACHEDSTEP(21680)
Step 6
Also removing the rownum limits return and doing a
SELECT s.name AS step_name, ps.id AS step_id, max((ps.tier*1000)+ps.sortorder) AS reached
FROM gchs_user_process_steps ups, gchs_process_steps ps, gchs_steps s
WHERE ups.gchs_process_step_id=ps.id AND
ps.gchs_step_id=s.id AND
ups.gchs_user_process_id=21680
GROUP BY s.name,ps.id,ps.tier, ps.sortorder
ORDER BY 3 DESC
give this result
STEP_NAME STEP_ID REACHED
Step 5 10020 3005
Step 6 10060 3004
Step 3 10002 1002
Step 1 10000 1
Edited by: user4935832 on 2008-sep-19 01:38ORDER BY 3 DESC) a
WHERE rownum <= 1 )
WHERE rnum >= 1;Just some thoughts.
1. You could replace "ORDER BY 3" by "ORDER BY reached"
2. the rownum <=1 and rnum>=1 will return only one row... I don't understand the second one.
Lastly, the difference might come from a duplicate value return by your MAX() function.
If there is two rows (or more) with same MAX, Oracle might return one row arbitrary.
To get the same row, you have to use some aggregation function like MAX() KEEP (DENSE_RANK LAST...).
Here a try for your query, obviously not tested :
SELECT max(substr(step_name,1,30)) keep (dense_rank last order by reached) as step_name,
max(step_id) keep (dense_rank last order by reached,step_name) as step_id,
max(reached) as reached
FROM (SELECT s.name AS step_name,
ps.id AS step_id,
max((ps.tier*1000)+ps.sortorder) AS reached
FROM gchs_user_process_steps ups,
gchs_process_steps ps,
gchs_steps s
WHERE ups.gchs_process_step_id=ps.id
AND ps.gchs_step_id=s.id
AND ups.gchs_user_process_id=21680
GROUP BY s.name,ps.id) a;Nicolas. -
Bug? using MAX() function on char(1) column returns something larger
details:
-- we have a complex nested query, where we are essentially returning the max() value into a variable
-- the max() function is being used on a char(1) column
-- where MAX() is part of an inner select, we have started getting
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
errors.
SELECT MAX(X) INTO var FROM ... works in 9i and 10g
SELECT X INTO var FROM (SELECT MAX(X) X FROM ... worked in 9i, does not work in 10g!
-- We never had problems with the code until upgrading to 10g release 2.
-- the Solution is to cast the final value with TO_CHAR(). The cast MUST be done at the outer most point of the select:
SELECT TO_CHAR(X) INTO var FROM (SELECT MAX(X) X FROM ... works
SELECT X INTO var FROM (SELECT TO_CHAR(MAX(X)) X FROM ... causes an error!
The following script demonstrates the issue, and includes the solution:
* October 3, 2006
* Possible SQL bug introduced with Oracle 10G
* Natalie Gray DBA/Developer, Environment Canada
* Description:
* Have discovered a problem with using the MAX() function
* on columns of type char(1)
* only an issue when used in an inner select
* solution (see test 4)
CREATE TABLE SQL_BUG_TEST
X NUMBER,
Y NUMBER,
Z CHAR(1)
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,1,'A');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,1,'B');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,2,'C');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,2,'D');
DECLARE
TYPE REC IS RECORD (
x SQL_BUG_TEST.X%TYPE,
y SQL_BUG_TEST.Y%TYPE,
z SQL_BUG_TEST.Z%TYPE
v_rec REC;
BEGIN
-- DISPLAY THE TABLE DATA
BEGIN
DBMS_OUTPUT.PUT_LINE('TABLE DATA:');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * FROM SQL_BUG_TEST ORDER BY X,Y,Z;');
FOR crs IN (SELECT *
FROM SQL_BUG_TEST
ORDER BY X,Y,Z) LOOP
DBMS_OUTPUT.PUT_LINE(':'||crs.X||':'||crs.Y||':'||crs.Z);
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 1
-- returning result from MAX into a variable when the MAX is in the outer most select
-- does not cause an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 1');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y');
FOR crs IN (SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y
ORDER BY X,Y,Z) LOOP
DBMS_OUTPUT.PUT_LINE(':'||crs.X||':'||crs.Y||':'||crs.Z);
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 2
-- returning MAX() from an inner select to an outer select and then into a variable
-- causes an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 2');
DBMS_OUTPUT.PUT_LINE('THIS DID NOT CAUSE AN ERROR WITH ORACLE 9i');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT * INTO v_rec
FROM
(SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 3
-- casting the result from MAX to char before returning to the outer select
-- still causes an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 3');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, to_char(MAX(Z)) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT * INTO v_rec
FROM
(SELECT X, Y, to_char(MAX(Z)) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 4 - SOLUTION
-- the return value of MAX must be cast with to_char at the point where it is assigned to
-- variable (outer most select)
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 4 SOLUTION');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT X, Y, TO_CHAR(Z) Z INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT X, Y, TO_CHAR(Z) Z INTO v_rec
FROM
(SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
END;I certainly looks like a bug, but you should raise an iTAR on Metalink since Oracle does not monitor this forum.
I was able to replicate your results on my 10.2.0.1 database.
There is an easier workaround than yours. Try
ALTER TABLE sql_bug_test MODIFY (z VARCHAR2(1));That seems to eliminate the problem on my instance.
John -
Exporting historical data to text file with MAX misses columns of data?
I am using Labview 7.1 with DSC module 7.1 and wants to export data to either excel format or .txt.
I have tried this with the historical data export in MAX, and also programmatically with the "write traces to spreadsheet file.vi" available in the DSC module. All my tags in my tag engine file (*.scf) are defined to log data and events. Both the update tag engine deadband and the update database are set to 0 %.
My exported excel or text file seems reasonalbe except that some columns of data are missing. I dont understand
why data from these tags are not in the exported files since they have the same setup in the (.scf) as other tags which are okay exported?
All defined tags can be seen using the NI hypertrend or MAX. Also the ones that are not correctly exported to file.
Appreciate comments on this.
Best regards,
Ingvald BardsenI am using LV and DSC 7.1 with PCI-6251 and max 4.2. In fact, just one column of values does not make sense. In attachment, follows the excel exported file. The last of column called ...V-002 that is the problem. I put probes for checking values but them shows correct. When the file is exported that to show values wrong.
The problem of missing values in column i solved putting 0% in field of deadband.
thank you for your help
Attachments:
qui, 2 de ago de 2007 - 132736.xls 21 KB -
How to Avoid Errors in Max Function When Data Contains Blank Cells
I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
Thanks,
NicI don't see a problem with "blank" (null string) cells mixed with duration cells. MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"? -
User defined function for removing wrong data ... !!!
Hi Experts,
I'm having a source data like this
1001 545 6895895 1584 654 5478
1002 525 6895895 5084 654 5472
1003 535 6895895 0584 654 5478
1004 545 6895895 5184 654 5478 4XXX &^%% 1004 545
1005 555 6895895 5824 654 5478 8547 0000 522# ##00
1006 565 6895895 5844 654 5478
1007 575 6895895 5845 654 5478
1008 585 6895895 5846 654 5478
Some times I get a wrong data in my source file (above 4 and 5 th rows) .
My requirement is to remove these kind of wrong lines(entire lines to be removed) whenever XI reads the data. For this what is the standard function i can use in mapping. I thought I can create my own function to remove such kind of false data lines. It would be helpful for me if some body provide me the java code.
Thanks very much.Hi Swarna,
1001 545 6895895 1584 654 5478
1002 525 6895895 5084 654 5472
1003 535 6895895 0584 654 5478
1004 545 6895895 5184 654 5478 4XXX &^%% 1004 545
1005 555 6895895 5824 654 5478 8547 0000 522# ##00
1006 565 6895895 5844 654 5478
1007 575 6895895 5845 654 5478
1008 585 6895895 5846 654 5478
is it the .txt file you are keeping. Or the input in your mapping.
You just Tell your requirement properly.
If it is input in Mapping. Map like this
input ----->subtring( starting position 0 andNumber of characters 30) ---->Output
substring is a standard Text function.
Thanks. -
How to use MAX() function with date field
Hi Frzz,
I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
Is there is any other way we can achieve this requirement in Graphical Calculation view?? Your suggestion will really help me.
Thank you.
Krishna.Hmm... what have you tried out so far?
Look, I took the effort and created a little example, just for you
Assume we have a table that contains the logon dates of users.
Every line contains the logon date and some info on the user.
Very much like a not-normalized log file could look like.
Now, the output we want is: one line per user with the most current logon time.
Not too difficult:
1. Have a aggregation node that gives you the distinct user details - one line for every user:
2. Have another aggregation node that gives you the last (MAX) logon date per user:
Finally you do a 1:1 join on the USER_ID and map the result to the output.
Easy as pie
- Lars -
Use COUNT or MAX functions inside of a query, and you have no data found
I'm writing a query with a COUNT and a MAX function.
SELECT li.id
, MAX(m.display_date)
, COUNT(*)
FROM li JOIN m ON (m.LIID=li.LIID)
WHERE m.DISPLAY_DATE < SYSDATE - 7
GROUP BY li.id;I would like to write a query that returns always a row foe each row in the table li.
If there are no records with the condition "WHERE m.DISPLAY_DATE < SYSDATE - 7", I would like to have a row with
- COUNT(*) = 0
- MAX(m.display_date) = TO_DATE('2010-06-08', 'YYYY-MM-DD'user600979 wrote:
I'm writing a query with a COUNT and a MAX function.
SELECT li.id
, MAX(m.display_date)
, COUNT(*)
FROM li JOIN m ON (m.LIID=li.LIID)
WHERE m.DISPLAY_DATE < SYSDATE - 7
GROUP BY li.id;I would like to write a query that returns always a row foe each row in the table li.
If there are no records with the condition "WHERE m.DISPLAY_DATE < SYSDATE - 7", I would like to have a row with
- COUNT(*) = 0
- MAX(m.display_date) = TO_DATE('2010-06-08', 'YYYY-MM-DD'In that case tell me what do you want to display in the ID column. That is the first column? -
Max() function in Data services
Hi Experts,
i'm using Data services (etl), and working on budget table(ms sql table),
1. the table has a field [budget amount] and [version_no],
2. before i extract the budget amount i need to know the highest version in [version_no] fields
3. can any body help me on this? i tried to use the script: ifthenelse(max(version-no),budget_amount, 0) but it retuns error when validation.
please help me on this:
thanks in advance
Archie72Hi,
Connect a Query transform say Query1 from the source table
Inside Query1
select MAX(version no) into the output. Do not select the other budget field into the output.
Connect another Query transform say Query2 from the source table. Connect the output of Query1 also into Query2.
Inside Query2:
Join the source table and Query 1 in where
Query1.version no = SourceTable.version no
Select version no and budget into Query 2 output and connect it to target table.
Assuming that the source table has only version number and budget. You might have to tweak and make use of Group By as required where you use the MAX() function. SourceTable mentioned in the where condition will be replaced with your exact source table name
Regards,
Suneer -
Hi,
I would like to know if it's possible to do a Max function between two dates ?
For instance I would like to do:
Date Y = Max (created date + 4 days) and (Date X + 3 days)
Thanks for your help,Thank you Dinesh for your fast reply.
My request refer to a field management/WF.. So as you mentionned it's not possible in a standard way.
But what kind of "other conditional statement" are you talking about?
Regards,
Vincent -
Since mountain lion I have noticed 3-4 columns of data missing from a Numbers file. I have fortunately been able to replace the total file from my iPad version but why has this happened. Makes me lose trust in Numbers
That would be strange.
-
i have created a procedure in a form that return summary columns (count,max) and it is based in a view which is created containing 2 select statement. the problem is the max function doesn't return the max date in the first select statment in the Form. but if i run it in sql it does. i think the trouble is because this feild is a companition of two feilds(contract_Date and sysdate) ... i will add the view and the procedure below so it would be clear. but my question is : if the sql return the right result why the form can't show it.
View ...
CREATE OR REPLACE VIEW ATN_DLEV_DCON_VIEW( EMP_ID,
REPORT,TYPE, DATE_FROM )
AS SELECT
ID,
'TO_RENEW' REPORT,
'ÊÌÏíÏ ÚÞÏ' TYPE,
CONTRACT_DATE DATE_FROM
FROM PRS_EMPLOYEE_PROFILE
WHERE TO_CHAR(ADD_MONTHS(SYSDATE,1),'MM')=TO_CHAR(EMPLOYMENT_DATE,'MM')
AND CONTRACT_TYPE = 2
AND EMP_STS_ID NOT IN (40, 28)
union
SELECT
EMP_ID,
'PayLev01' REPORT ,
'ÊÑÍíá ÅÌÇÒÉ' TYPE,
START_DATE DATE_FROM
FROM PRS_EMP_VAC_APPLICANTS
WHERE REC_STATUS in (1,5) and emp_id <> 187
Procedure
PROCEDURE P_SHOW_TASKS IS
V_COUNT NUMBER:=0;
V_CHK NUMBER;
BEGIN
SELECT COUNT(EMP_ID)
INTO V_CHK
FROM SEC_USERS
WHERE ID = :GLOBAL.USR;
IF V_CHK <> 0 THEN
SELECT DES_ARB
INTO :TASKS.DEPT_NAME
FROM PRS_DEPARTMENTS
WHERE ID = 6 ;
SELECT COUNT(DISTINCT TYPE)
INTO V_COUNT
FROM ATN_DLEV_DCON_VIEW1, SEC_GROUPS
WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) AND ID = 'ADM';
IF V_COUNT <> 0 THEN
SHOW_VIEW('CV_TASKS');
GO_BLOCK('TASKS');
FIRST_RECORD;
FOR I IN (SELECT report, COUNT(EMP_ID) COUNT, TYPE, MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) GROUP BY REPORT, TYPE) LOOP
:TASKS.REPORT := I.REPORT;
:TASKS.COUNT := I.COUNT;
:TASKS.TYPE := I.TYPE;
:TASKS.MAX_DATE := I.DATE_FROM;
V_COUNT := V_COUNT - 1;
IF V_COUNT <> 0 THEN
NEXT_RECORD;
ME(V_COUNT);
END IF;
END LOOP;
END IF;
ELSE
SELECT COUNT(DISTINCT TYPE)
INTO V_COUNT
FROM ATN_DLEV_DCON_VIEW1;
IF V_COUNT <> 0 THEN
SHOW_VIEW('CV_TASKS');
go_block('TASKS');
FIRST_RECORD;
FOR I IN (SELECT REPORT, COUNT(EMP_ID) COUNT, TYPE , MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 GROUP BY REPORT, TYPE) LOOP
:TASKS.REPORT := I.REPORT;
:TASKS.COUNT := I.COUNT;
:TASKS.TYPE := I.TYPE;
:TASKS.MAX_DATE := I.DATE_FROM;
V_COUNT := V_COUNT - 1;
IF V_COUNT <> 0 THEN
NEXT_RECORD;
ME(V_COUNT);
END IF;
END LOOP;
END IF;
END IF;
END;thank you for your reply ...well, this is what is confusing me, it works in sql and it works in forms as well but not with the two date variables (To_RENEW, START_DATE)... if you had a look to the view, i posted the wrong one here but down below will be the one i am using. in the first select statment the date is a companition of CONTRACT_DATE
(to get the month and day of renewal date of the contract because i don't have it as a COLOUM in the table ) concatonated with sysdate to get only the year "IT IN BOLD IN THE VIEW" and in the second select statment it is availabe in the table, and it is returned correclty in sql and procedure of the form as well. so if there is something worng with procedure the other date will not be shown this is the part of the procedure that fill the form with data
(SELECT report, COUNT(EMP_ID) COUNT, TYPE, MAX(DATE_FROM) DATE_FROM FROM ATN_DLEV_DCON_VIEW1 WHERE EMP_ID IN (SELECT ID FROM PRS_EMPLOYEE_PROFILE) GROUP BY REPORT, TYPE) LOOP
:TASKS.REPORT := I.REPORT;
:TASKS.COUNT := I.COUNT;
:TASKS.TYPE := I.TYPE;
:TASKS.MAX_DATE := I.DATE_FROM;
V_COUNT := V_COUNT - 1;
IF V_COUNT <> 0 THEN
NEXT_RECORD;
this part ( MAX(DATE_FROM) works with the second select statment of the view and it doen't work for the first one in the form only but it does in sql foe both
i am waitin 4 ur eply
here is the right view
CREATE OR REPLACE VIEW ATN_DLEV_DCON_VIEW( EMP_ID,
REPORT,TYPE, DATE_FROM )
AS SELECT
ID,
'TO_RENEW' REPORT,
'ÊÌÏíÏ ÚÞÏ' TYPE,
TO_CHAR(SYS_DATE,'YYYY') || '/'|| TO_CHAR(CONTRACT_DATE,'MM','DD')DATE_FROM
FROM PRS_EMPLOYEE_PROFILE
WHERE TO_CHAR(ADD_MONTHS(SYSDATE,1),'MM')=TO_CHAR(EMPLOYMENT_DATE,'MM')
AND CONTRACT_TYPE = 2
AND EMP_STS_ID NOT IN (40, 28)
union
SELECT
EMP_ID,
'PayLev01' REPORT ,
'ÊÑÍíá ÅÌÇÒÉ' TYPE,
START_DATE DATE_FROM
FROM PRS_EMP_VAC_APPLICANTS
WHERE REC_STATUS in (1,5) and emp_id <> 187 -
I used 30 day trial of Acrobat XI and all the functions work perfectly. But, when I buy the program (either download or disk) my PDF that export to Excel is not working. The excel columns and data are not properly aligned as they should be. The Trial version aligns everything perfectly. What is happening? I use a MAC 10.9.5. But this shouldn't matter because the trial version works perfectly. Can anyone help?
just found out that this is posted in the wrong section.
-
Max function in select statemnt
Hi,
Can someone help me with what is wrong in the following query...How to use the max function
in ABAP program select statement??
Thanks..
LOOP AT IT_ANLA_ANLZ INTO WRK_ANLA_ANLZ.
SELECT KANSW
FROM ANLC INTO TABLE IT_ANLC WHERE GJAHR IN ( SELECT MAX(GJAHR) FROM ANLC ) and ANLN1 = WRK_ANLA_ANLZ-ANLN1
AND BUKRS = WRK_ANLA_ANLZ-BUKRS .
APPEND IT_ANLC.
ENDLOOP.Hi,
You have write your select query once,
and then loop on the internal table into
which data will get populated for its display.
SELECT KANSW
FROM ANLC INTO TABLE IT_ANLC WHERE GJAHR IN
( SELECT MAX(GJAHR) FROM ANLC ) and ANLN1 = WRK_ANLA_ANLZ-ANLN1
AND BUKRS = WRK_ANLA_ANLZ-BUKRS .
Then loop at internal table:
LOOP AT IT_ANLA_ANLZ INTO WRK_ANLA_ANLZ.
write: / wrk_anla_anlz-fields.
Endloop.
Hope it helps
Regards
Mansi
Maybe you are looking for
-
Can not import MXF files into Final Cut Pro
I am full of anger and frustration!!! I purchased final cut pro only to find out that it WILL NOT import MXF files. How insane is that? ADOBE - NO PROBLEM. Then I had to go back to YOUR STORE and buy two different file converter applications before I
-
I want to disable the encryption for my backups. Where do I find that?
I want to disable the encryption in ITunes so I can work with restoring my new Iphone 5s and my new Ipad Air. Where do I find that?
-
Trying to pass Oracle array/object type to Java
I have a Java class with two inner classes that are loaded into Oracle: public class PDFJ public static class TextObject public String font_name; public int font_size; public String font_style; public String text_s
-
IPhoto shows an exclamation mark inside a triangle when trying to view the image
When trying to access the photos, a triangle with an exclamation mark pops up and I am unable to drag or view the photo. The triangle looks like this
-
If i select AHCI or RAID, it can't detects the HDD. I can only use default settings, IDE. In Win7, no AHCI or SATA controller in Device Manager?? Is my board faulty?