Criteria for querying two related tables

125 views Asked by At

I got my select statement like this right now:

  SELECT pernr reinr pdatv pdatb accdt pdvrs abrec FROM ptrv_perio
INTO CORRESPONDING FIELDS OF TABLE lt_ptrv_perio
WHERE ( abrec EQ '2'
        AND pdatv GE pa_begda
        AND pdatb LE pa_endda )
OR    ( abrec EQ '3'
        AND accdt GE pa_begda
        AND accdt LE pa_endda ).

The thing is the attribute accdt from my second condition is in another table. Is there a way I can get it and directly use it in the select statement? The problem I got is, that I can't get the value before the select, because I get the right travel ID just in that select.

I hope I was able to explain my issue. Thanks for any hints! :)

1

There are 1 answers

0
Dyrdek On

The following code solved my issue:

SELECT p~pernr p~reinr p~pdatv p~pdatb p~accdt p~pdvrs p~abrec
FROM ptrv_perio AS p INNER JOIN ptrv_head AS h ON p~reinr = h~reinr
INTO CORRESPONDING FIELDS OF TABLE lt_ptrv_perio
WHERE ( p~abrec EQ '2'
        AND p~accdt GE pa_begda
        AND p~accdt LE pa_endda )
OR    ( p~abrec EQ '3'
        AND h~dates GE pa_begda
        AND h~dates LE pa_endda ).

I'm selecting from table p while on criteria in the OR-Statement comes from table h. Hope this will help somebody besides me :)