Application Development 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: 

select statement

Former Member
0 Kudos

hi all,

may i know how to write a select statement to select datum2 if datum2 is greater than datum1 else select datum1.

datum1 and datum2 in tableB. tableA inner join with tableB.

thanks

5 REPLIES 5

anversha_s
Active Contributor
0 Kudos

hi,

1. select the records into an internal table.

2. Use READ statement to fetch datum1 and datum2 rom that itab

3. use IF condition to find the bigger one among the dates.

Rgds

Anver

0 Kudos

Hi,

I think you need two queries since we cannot have the select clause dynamic.

Ideal would be SELECT DATUM2 FROM TABLEA INNER JOIN TABLEB ON

-


-


WHERE DATUM2> DATUM1 AND.....

if sy-subrc of this is not 0 then directly fetch DATUM1 with same where clause.

Regards,

Sesh

0 Kudos

Hi,

I think you need two queries since we cannot have the select clause dynamic.

Ideal would be SELECT DATUM2 FROM TABLEA INNER JOIN TABLEB ON

-


-


WHERE DATUM2> DATUM1 AND.....

if sy-subrc of this is not 0 then directly fetch DATUM1 with same where clause.

Regards,

Sesh

Former Member
0 Kudos

i think it is not possible in sql...

but you can try like this..

data : v_date1 like sy-datuem,

v_date2 like sy-datuem.

select bbate1 bdate2 into (v_date1, v_date2) from dbtab as a inner join dbtab1 as b on af1 = bf1 where <condn>

if v_date1 ge v_date2.

itab-date = v_date1.

else.

itab-date = v_date2.

endif.

append itab.

endselect.

regards

shiba dutta

Former Member
0 Kudos

hi

Selection should be unique (Fields) when you are hitting the database table. Even if you work around some way of selectiong it, it would not be suggestable. So you better get all the records into an internal table and then use your conditions to modify the same or have an other internal table to have the actual data.

or.

1.

Select dat1

from tab1

into table itab

where dat1 gt dat2.

2.

Select dat2

from tab1

appending table itab

where dat1 lt dat2.

-

Santosh