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

select query condition...

Former Member
0 Likes
1,116

Hello,

I need to pick up a value from a table which is closest to another value.

For eg i need to pick up a qty ie closest to 6 and not equal to 6.

It might be 5 or 7.(which ever closest is available)

is there any other way to give a where condition than the not equal to....?

thanks,

Larry

Hello,

I need to pick up a value from a table which is closest to another value.

For eg i need to pick up a qty ie closest to 6 and not equal to 6.

It might be 5 or 7.(which ever closest is available)

is there any other way to give a where condition than the not equal to....?

thanks,

Larry

6 REPLIES 6
Read only

Former Member
0 Likes
1,096

You can try this -

Get all the data into internal table. Loop at the internal table and check the condition for the specified field.

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,096

Hi

U can use round and trnacate function.

suppose u have value 4.5 take to value

4 and 5 use <b>BETWEEN</b> condition in where condition.

this may be useful.

regards

vinod

Read only

Former Member
0 Likes
1,096

Hi

I don't think, you need to load all data and then control which is the closest value, something like following code:

CHECK_VALUE = 6.

SELECT * FROM <TABLE> WHERE ......

DELTA = ABS( <TABLE>-QTY - CHECK_VALUE ).

IF DELTA < DELTA_OLD.

DELTA_OLD = DELTA.

OK_QTY = <TABLE>-QTY.

ENDIF.

ENDSELECT.

Max

Read only

0 Likes
1,096

Max,

will it not be good to do this processing using internal tables rather than in SELECT - ENDSELECT.

We can define lower range and higher range. And delete data from internal table which does not fall in this criteria. (< lower range and > higher range)

ashish

Message was edited by: Ashish Gundawar

Read only

0 Likes
1,096

Hi

Yes of course!

I wrote only an example to explain the logic.

Max

Read only

Former Member
0 Likes
1,096

Well I shall try...Thanks guys for your replies...

Larry