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 statment - where condition

Former Member
0 Kudos
118

Hi,

i have data in a table where for a field it has data ending with 123, 124, 125 etc .

in my select query i want to select data based on the ending data like 123, 124 , 125 .

example : abc123, xyz123 . i need to pull all data ending with 123.

how do i write that in my select statment .

can anyone let me know . thanks in advance.

Ry.

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos
96

Hi,

Please try this.


concatenate '%' var1 into var2.

SELECT * 
FROM <ztable> 
INTO TABLE <itab> 
WHERE <field1> = var1 
  AND <field2> like var2.

Regards,

Ferry Lianto

Please reward points if helpful.

7 REPLIES 7

Former Member
0 Kudos
96

Hi,

Use LIKE statement..

Ex..

SELECT * FROM xxx

WHERE field LIKE '%123'.

Thanks,

Naren

0 Kudos
96

naren ,

thank you for the reply , the problem is i am passing this 123 into a character field .

ex: 123 to VAR

so in my query i gave as '%VAR'. the query was unsucessful . am i missing something , let me know

Regards,

Ry

ferry_lianto
Active Contributor
0 Kudos
96

Hi,

Please try this.


RANGES: R_FIELD FOR ZTABLE-FIELD.

R_FIELD-SIGN = 'I'.
R_FIELD-OPTION = 'CP'.
R_FIELD-LOW = '*123'.
APPEND R_FIELD.

R_FIELD-SIGN = 'I'.
R_FIELD-OPTION = 'CP'.
R_FIELD-LOW = '*124'.
APPEND R_FIELD.

R_FIELD-SIGN = 'I'.
R_FIELD-OPTION = 'CP'.
R_FIELD-LOW = '*125'.
APPEND R_FIELD.

SELECT FIELD 
INTO TABLE ITAB
FROM ZTABLE
WHERE FIELD IN R_FIELD.

Regards,

Ferry Lianto

0 Kudos
96

Hi Ferry Lianto ,

thank you for your reply my req is like this

move *123 into Var2. this is of char type C .

SELECT * FROM <table > INTO ,itab> WHERE <table-field> = var1 AND <table-field1> = ' %var2' .

but this is not working , can you let me know where exactly is the issue .

ferry_lianto
Active Contributor
0 Kudos
96

Hi,

Pleas try this.



data: var2 like ztable-field2.

move '%123' to var2.
 
SELECT * 
FROM <ztable> 
INTO TABLE <itab> 
WHERE <field1> = var1 
  AND <field2> like var2.

Regards,

Ferry Lianto

0 Kudos
96

Ferry,

Here i have to move '%var1' to var2 as var1 is dynamic value .

so i am not able to populate the content of the variable.

can you help me out on this .

Ry.

ferry_lianto
Active Contributor
0 Kudos
97

Hi,

Please try this.


concatenate '%' var1 into var2.

SELECT * 
FROM <ztable> 
INTO TABLE <itab> 
WHERE <field1> = var1 
  AND <field2> like var2.

Regards,

Ferry Lianto

Please reward points if helpful.