Skip to Content
author's profile photo Former Member
Former Member

select statement

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Jan 29, 2007 at 09:02 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 29, 2007 at 09:05 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 29, 2007 at 09:05 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2007 at 09:06 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2007 at 09:08 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.