Reputation: 149
I have a query:
for each a where ...,
each b where ...,
each c where ...,
break by c.xxx by c.yyy by c.zzz.
I need the break by's to vary according to user input.
When I try to define a query:
def query qa for a, b, c.
if ... then open qa for each a... (as above)
then it won't compile because:
BREAK requires query be defined SCROLLING. (14283)
How can I set variables for the "break by"?
Upvotes: 0
Views: 1605
Reputation: 14020
Look up "query-prepare". That's the magic that lets you completely customize your query.
I happened to be writing such a query this morning:
/* dyn.p
*/
define variable tbl as character no-undo.
define variable brk as character no-undo.
define variable b as handle no-undo.
define variable q as handle no-undo.
tbl = "customer".
brk = "state".
create query q.
create buffer b for table tbl.
q:set-buffers( b ).
q:query-prepare( "for each " + tbl + " break by " + brk ).
q:query-open.
q:get-next().
do while q:query-off-end = false:
if q:first-of( 1 ) then clear all.
display
b:buffer-field( 'CustNum' ):buffer-value()
b:buffer-field( 'Name' ):buffer-value()
b:buffer-field( 'State' ):buffer-value()
with
down
.
down 1.
q:get-next().
end.
return.
Run the code above against "sports2000".
Upvotes: 1