Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

selecting single record from Table

anuja_s
Participant
0 Likes
824

Hi Experts

My code is as below:

IF S_COUNTER_DATAPAKID = 0.

OPEN CUSRSOR WITH HOLD S_CURSOR FOR

SELECT OBJID AEDTM FROM HRP1000

         
WHERE PLVAR = 'A1' AND OTYPE = 'S' AND ENDDA = '99991231'.


   
ENDIF.       

here, i am getting more than one AEDTM for 1 OBJID. But, i want only latest date(AEDTM) , how to change this code. I am adding sort statement but it is not allowing to add SORT before SELECT.

Please guide.

Thanks in advance.

7 REPLIES 7
Read only

Former Member
0 Likes
789

Hi Anuja ;

Please check the HRP1000-LANGU field, maybe this field can filter the result.

Regards

Özgün

Read only

former_member194739
Active Participant
0 Likes
789

Dear Anuja,

Use select single in SELECT statement with where conditions.

Regards,

Abbas.

Read only

0 Likes
789

Hi

I can not use SELECT SINGLE and MAX, as it is not allowing to use inside CURSOR.

Read only

0 Likes
789

You not need to use SELECT MAX inside CURSOR but use SUB Query, is different.

In your case the code becomes:

         OPEN CURSOR WITH HOLD S_CURSOR FOR

         SELECT OBJID AEDTM FROM HRP1000
         
WHERE PLVAR = 'A1' AND OTYPE = 'S' AND ENDDA = '99991231'

         

          AND AEDTM = ( SELECT MAX( AEDTM ) FROM HRP1000 WHERE

          PLVAR = 'A1' AND OTYPE = 'S' AND ENDDA = '99991231' ).


Regards,


Angelo.

Read only

former_member302911
Active Participant
0 Likes
789

In Where condition try to use SUB Query:


... AND AEDTM = ( SELECT MAX( AEDTM ) FROM HRP1000 WHERE ... ).


Regards,

Angelo.

Read only

Former Member
0 Likes
789

Select the max date with single statement

Read only

0 Likes
789

With subquery of course