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

Select Query

Former Member
0 Likes
642

How will write a select query where a date field should be maximum out of all values present for that field?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
618

Hi,

Use the 'MAX' function.

select MAX ( <fieldname> )

from <tablename>

into <variablename>

based on the conditions.

The above function selects the maximum value of the given field from the table.

Reward if helpful,

Sharin.

3 REPLIES 3
Read only

bpawanchand
Active Contributor
0 Likes
618

hi

use aggregate function MAX on that praticular date field

sample snippet

SELECT

MAX( erdat )

INTO ( w_d )

FROM mara.

ENDSELECT.

observe the MAX aggregate funtion

regards

pavan

Read only

Former Member
0 Likes
618

hi yogesh,

Use the aggregate MAX addition with date field.

MAX( [DISTINCT] col ) - Determines the maximum value of the value in the column col in the resulting set or in the current group.

Example

DATA: name     TYPE scustom-name, 
      postcode TYPE scustom-postcode, 
      city     TYPE scustom-city, 
      max      TYPE sbook-loccuram. 

SELECT scustom~name scustom~postcode scustom~city 
         MAX( sbook~loccuram ) 
       INTO (name, postcode, city, max) 
       FROM scustom INNER JOIN sbook 
         ON scustom~id = sbook~customid 
       WHERE sbook~fldate BETWEEN '20010101' AND '20011231' AND 
             sbook~carrid   = 'LH '                         AND 
             sbook~connid   = '0400' 
       GROUP BY scustom~name scustom~postcode scustom~city 
       ORDER BY scustom~name. 
  WRITE: / name, postcode, city, max. 
ENDSELECT.

Best of luck,

Bhumika

Read only

Former Member
0 Likes
619

Hi,

Use the 'MAX' function.

select MAX ( <fieldname> )

from <tablename>

into <variablename>

based on the conditions.

The above function selects the maximum value of the given field from the table.

Reward if helpful,

Sharin.