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

Problem in Dynamic Where clause..

Former Member
0 Likes
462

Hello All,

I have a requirement in which i have to do a select statement where (Field1 = 'X') and (Field2 = 'A' or Field2 = 'B').

But if i write it directly,

select * from Ztable into table itab where Field1 = 'X' and Field2 = 'A' or Field2 = 'B'.

Then I am not getting the expected result.

instead i need something which tells the where clause to do OR operation first and then AND operation..

Any ideas ??

Thanks in advance.

Tatvagna Shah.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
442

Hi,

Please try this.


select * 
from Ztable 
into table itab 
where Field1 = 'X' and ( Field2 = 'A' or Field2 = 'B' ).

Regards,

Ferry Lianto

Hello All,

I have a requirement in which i have to do a select statement where (Field1 = 'X') and (Field2 = 'A' or Field2 = 'B').

But if i write it directly,

select * from Ztable into table itab where Field1 = 'X' and Field2 = 'A' or Field2 = 'B'.

Then I am not getting the expected result.

instead i need something which tells the where clause to do OR operation first and then AND operation..

Any ideas ??

Thanks in advance.

Tatvagna Shah.

3 REPLIES 3
Read only

Former Member
0 Likes
443

Hi,

Please try this.


select * 
from Ztable 
into table itab 
where Field1 = 'X' and ( Field2 = 'A' or Field2 = 'B' ).

Regards,

Ferry Lianto

Read only

0 Likes
442

Hi,

Actually...just got a hint at almost the same time you answered...!!

Still 10 points for you....Just coz, you were the only one to reply.

Thanks.

Tatvagna.

Read only

0 Likes
442

Also, you must remember that parentheses and operators are keywords, and must therefore be preceded and followed by at least one space.