>>>>PART # PART DESCR QTY >>>>'ABC' Abc Part 1 >>>>'CBS' Cbs Part 2 >>>>'NBC' Nbc Part 5 >>>>'ESPN" ESPN Part 0 >>>>NFL NFL Part 10 >>>>>>>>
>>>create cursor x (qty int) >>>for k=1 to 100 && max(qty) >>> insert into x values (m.k) >>>next >>>select a.* from table a join x on x.qty <= a.qty into ... >>>>>
Local jsel jsel=Select() *-- create the test cursor or table Create Cursor part_test (part_numb c(10), part_desc c(20), qty i) Insert Into part_test (part_numb, part_desc, qty) Values ('ABC','Abc Part', 1) Insert Into part_test (part_numb, part_desc, qty) Values ('CBS','Cbs Part', 2) Insert Into part_test (part_numb, part_desc, qty) Values ('NBC','Nbc Part', 5) Insert Into part_test (part_numb, part_desc, qty) Values ('ESPN','ESPN Part', 0) Insert Into part_test (part_numb, part_desc, qty) Values ('NFL','NFL Part', 10) *-- one line of sql with a couple of UDF and union clause SELECT part_test.* ; FROM part_test ; WHERE ; .f. AND ; part_test.part_numb in (SELECT part_expand_create() as xtest FROM part_test WHERE .f.) ; UNION ALL ; Select part_test.* ; FROM part_test ; join part_expand ; ON part_test.part_numb=part_expand.part_numb ; WHERE ; part_test.part_numb in (SELECT part_udf(part_numb) as test FROM part_test) ; INTO Cursor tresult Browse Select(jsel) Return *-- first select returns zero records but creates cursor for adding records PROCEDURE part_expand_create Select * From part_test Where .F. Into Cursor part_expand Readwrite RETURN '' endpro *-- UDF loops through each record of the select Procedure part_udf Lparameters tpart_numb LOCAL orecord Local array tempexpand[1,1] Select part_test GO bott Locate For part_numb = m.tpart_numb If Found() SCATTER NAME orecord Local i If orecord.qty>=1 For i = 1 To orecord.qty *-- test, prior to adding SELECT COUNT(part_numb) FROM part_expand WHERE part_numb=m.orecord.part_numb inTO ARRAY tempexpand IF _tally>0 AND tempexpand[1]<orecord.qty Insert Into part_expand From Name orecord ENDIF RELEASE tempexpand Endfor ENDIF RELEASE orecord Select part_expand RETURN part_expand.part_numb Endif Endproc