2

here is the sample that i want to ask:

FOR EACH table-name.... NO LOCK BY (IF TRUE THEN sort-this ELSE sort-that + sort-that2).

END.

This would result in an error.

if it is just

FOR EACH .. NO LOCK BY (IF TRUE THEN sort-this ELSE sort-that).
END.

then there is no error. Progress would accept the code

What is need is if condition is true then sort by one field else sort by two or more fields

noob
  • 165
  • 3
  • 18
  • I'm confused by what the issue is, and the answers you've had so far - using Progress 9.1e, I can construct a for each with `BY ( IF cond THEN expr ELSE expr )` without any errors. – Screwtape Jul 21 '16 at 09:42
  • The BY ( IF cond THEN expr ELSE expr ) has no issue on my end. the problem is BY ( IF cond THEN expr ELSE expr + expr2 ) will result in an error. or should my approach be `BY ( IF cond THEN expr ELSE expr2 ) BY (IF cond then TRUE else othr-expr) ` having two BY's – noob Jul 22 '16 at 01:43

3 Answers3

2

If you are in a modern enough version of Progress, then you could construct a dynamic query. This will be more efficient in terms of run time as well as getting you round your problem as having IF statements in your query predicate will make index selection hard.

QueryString = "for each table no-lock...".
if true then 
  QueryString = QueryString + " by sort-this".
else
  QueryString = QueryString + " by sort-that by sort-other".

create query QueryHandle.
QueryHandle:add-buffer(buffer table:handle).
QueryHandle:query-prepare(QueryString).
QueryHandle:query-open.
do while QueryHandle:get-next():
  /*some stuff*/
end.
QueryHandle:query-close.
delete object QueryHandle.
jdpjamesp
  • 762
  • 7
  • 19
  • We havent tried dynamic query in our code. so i cant really understand it. but i will study this one.. thanks – noob Jul 22 '16 at 01:44
1

As per the previous reply, this is not supported.

Typically, you'd have to prepare the result into a temp-table first, using a logical field in the temp-table for the result of your IF THEN ELSE expression.

Mike Fechner
  • 6,627
  • 15
  • 17
0

Unfortunately, this syntax is not supported. As per the documentation, BREAK/BY expects an expression following it but not a statement.

Austin
  • 1,237
  • 1
  • 11
  • 22