0
votes

I can do this with a string and it works great. example:

for each emp no-lock where
   lookup(emp.name, "james,john,kerry,david") <> 0:
  /* Do something */
end.

Now I have emp.ID that is not a string (it's an integer) how can I do where IN ? I tried similar method as above. but it gives me an error, it says "incompatible data types"

for each emp no-lock where
    lookup(emp.ID, "1,5,89") :
  /* Do something */
end.

how do I do this ? thank yo u

2

2 Answers

2
votes

OpenEdge has a SQL-92 engine but you aren't using that. You are using the 4gl engine. There is some limited SQL-89 syntax embedded inside the 4gl engine but it is a bad idea to try to use it. It only leads to pain and suffering

The 4gl has no IN function. To do what you are trying to do with a variable set of integers you would probably want to first create a temp-table and then join the TT with your real table. Something like this:

define temp-table tt_intList
  field f1 as integer
.

create tt_intList.
tt_intList.f1 = 1.

create tt_intList.
tt_intList.f1 = 5.

create tt_intList.
tt_intList.f1 = 89.

for each tt_intList, each emp no-lock where emp.Id = tt_intList.f1:
  display emp.Id emp.name.
end.
0
votes

In a large DB table, to make good use of indexes:

FOR EACH emp NO-LOCK WHERE emp.ID = 1 OR emp.ID = 5 OR emp.ID ? 89

A lazy coder in a small table might do:

FOR EACH emp NO-LOCK WHERE LOOKUP (STRING(emp.ID), "1,5,89") > 0