BY expression

BadSector

New Member
Hi All,

Total newbie, so please be kind.

Code:
def var sortby as char.

sortby is set in a form. (EG. id, name, date, group etc)
I output sortby and can confirm that it is correctly set.

Code:
OPEN QUERY brdquery FOR EACH brd [COLOR=red]BY sortby[/COLOR].

As you can see I need the value in sortby resolved to a specific column name, so as to display the resultset in that order.

Problem : If I hardcode "BY date" "BY name" etc. it works fine. But when I introduce the sortby variable containing the sort criteria it doesn't.

I've checked a lot of threads but couldn't find an answer, sorry if I missed it. :o
 
U can achieve it by using an include file ...

write the open query statement in a .i file and

pass ur sortby var as an agument to that...
 
Thanks for your quick reply, vigneshbr!

Is using an include the only way? It seems longwinded for a feature that seems elementary. I could make a procedure for every possible value of sortby - but that be repetitive.
 
Code:
case sortby:
  when "date" then OPEN QUERY brdquery FOR EACH brd BY date.  /* you can't really be using "date" for a field name.. */
  when "name" then OPEN QUERY brdquery FOR EACH brd BY name.
  /* ... */
end.

or:

Code:
define variable qh as handle no-undo.
define variable wc as character no-undo initial "FOR EACH brd ".

qh = query brdquery:handle.
qh:query-prepare( wc + "by " + sortby ).
qh:query-open().
 
Thanks Tom!

Went with the case. WORKED PERFECTLY. I tried the include approach but it didn't seem to work.

I'm not sure the include was a valid solution, I passed it the variable but still had no luck.

From memory, I tried :

main prog
Code:
{include.i &sortby=sortby}

include.i
Code:
OPEN QUERY brdquery FOR EACH brd BY {&sortby}.

Was this what you meant vigneshbr?
 
Back
Top