selectabapopensql

And + Or in one Select-Statement


In my select statement I chain different conditions with AND. Now I need for one condition an OR. How can I add this for just this one Attribute without affecting the other AND-statements before? That's my coding:

SELECT pernr reinr pdatv pdatb pdvrs abrec FROM PTRV_PERIO INTO CORRESPONDING FIELDS OF TABLE lt_ptrv_perio WHERE pdatv GE pa_begda AND pdatb LE pa_endda AND abrec EQ '2'.

For the last condition abrec EQ '2' I need an OR as well, like abrec EQ '2' OR '3'. How can I add this the best way without affecting the other ANDs?

Thanks for your hints!


Solution

  • Use parentheses:

    EDIT: Seems like you need to add spaces after and before the brackets See this related question.

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