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: 

how to get last 5 digits of a 22 digit number in a select query

Former Member
0 Kudos
1,121

HI All,

I am having a requirement where i need to join two database tables where there is only one field on which i can put an inner join, objnr from one table and valuestrng from other and last 5 digits of objnr can be compared with valuestrng, in a select query how can we get last 5 digits of 22 digit number.can anybody suggest the query please.

6 REPLIES 6

anversha_s
Active Contributor
0 Kudos
315

hi,

pls close multiple thread, the same question is answered

so another way


data: last_5(5) type c.
 
last_5 = v_data +  16(5).

rgds

Anver

Former Member
0 Kudos
315

Hi Shilpa ,

You cannot use offset in select statment , so the solution i would suggest select the data saperately , insted of using joins.

Regards

Arun

Former Member
0 Kudos
315

if u compare it in join itself it will give syntax error like,

filed is not defined in the DATA .

if u work with for all entries in, then also it wil give syntax error like, the two fileds to be compared should have same type and length.

so its better to take the data in an internal table, and compare with loop and can store into another internal table.

Former Member
0 Kudos
315

DATA : TVALUESTRING(5).

TVALUESTRING = OBJNR+16(5).

IN YOUR SELECT QRY

SELECT .....FROM <DBTAB> INTO.....WHERE VALUESTRING LIKE TVALUESTRING.

IF OBJNR VALUE IS NOT FIXED.

THEN USE STRLEN TO FIND OUT THE LENGTH OF OBJNR AND SUBTRACT 5 FROM THAT NOW TAKE THAT VALUE FROM OBJNR TO TVALUESTRING

REGARDS

SHIBA DUTTA

Former Member
0 Kudos
315

data: val(5).

val = variable+16(5).

select ........... from... into...... where objnr = val.

Cheers.

Former Member
0 Kudos
315

Hi shilpa,

In select statement you can not apply offset.

So select the 2 queries seperately.