0

I only have access to write a 4gl query after Where(. Is it possible to write a nested query to search in a completely different table?

For example

**FOR EACH WORK_ORDER WHERE(**

//my query starts on this line
1=1 and 
( for each purchase_order where key <> '123' end)

This obviously does not work, but is it possible to make it work? This query will give me ERROR: PREPARE syntax is {FOR|PRESELECT} EACH OF..WHERE" (7324)

Baked Inhalf
  • 3,375
  • 1
  • 31
  • 45

2 Answers2

2

No, it's not possible. The query needs to be aware of all it's buffers. If the only thing you can manipulate is the actual WHERE-clause it won't be enough.

This is how it can be done, but you need to manipulate more than just the where:

DEFINE QUERY q1 FOR WORK_ORDER, PURCHASE_ORDER.

QUERY q1:QUERY-PREPARE("FOR EACH WORK_ORDER, EACH PURCHASE_ORDER WHERE PURCHASE_ORDER.id = WORK_ORDER.id" ).

QUERY q1:QUERY-OPEN().

QUERY q1:GET-FIRST.

IF AVAILABLE work_order THEN DO:
    DISP work_order.
END.
ELSE DO:
    DISP "no work_order".
END.

IF AVAILABLE purchase_order THEN DO:
    DISP purchase_order.
END.
ELSE DO:
    DISP "no purchase_order".
END.

QUERY q1:QUERY-CLOSE.
Jensd
  • 7,886
  • 2
  • 28
  • 37
0

You could try using a join.

FOR EACH WORK_ORDER NO-LOCK WHERE... , EACH PURCHASE_ORDER WHERE PURCHASE_ORDER.key <> '123'
Ian Stewart
  • 635
  • 1
  • 7
  • 20