Article ID: 119354
Article Last Modified on 12/1/2003
PARAMETERS parentkey, childalias, string_exp
*parentkey is the field that all tables are indexed on.
*string_exp is the field in the child, must be a character expression
STORE "" TO ret_val
STORE ALIAS() TO was_alias &&parent table
m_exact=SET("EXACT")
SET EXACT ON &&this is necessary for INLIST
one2many=INLIST(UPPER(childalias),UPPER(SET("SKIP")))
SELECT (childalias)
IF NOT one2many
SEEK EVALUATE(was_alias + "." + parentkey)
ENDIF
IF FOUND() && are there related child records?
SCAN WHILE EVALUATE(childalias + "." + parentkey) = ;
EVALUATE(was_alias + "." + parentkey)
* get the data from the current record in the child
STORE ret_val + EVALUATE(string_exp) ;
+ CHR(13) + CHR(10) TO ret_val
* add carriage return & linefeed
ENDSCAN
ENDIF
SELECT (was_alias)
SET EXACT &m_exact
* ret_val is now a concatenation of child records, separated by CR/LF
RETURN ret_val
IIF(is_newkey=1,chldlst("code","child1","str(sales,10,2)"),"")
The expression for the second field is:
IIF(is_newkey=1,chldlst("code","child2","str(sales,10,2)"),"")
For both fields, do one of the following:USE customer IN 1 USE invoices IN 2 COPY TO inv2 USE inv2 IN 3The following SELECT-SQL statement could be used to join these tables into a cursor file that could then be used in a report. The resulting cursor will have all the related records for the first child, followed by the related records for the second child for each parent record. In this example, a character field is used to indicate from which child table the data comes and to further illustrate the point.
SELECT customer.cno, customer.contact, "child#1", invoices.ino, ;
invoices.idate ;
FROM customer, invoices ;
WHERE customer.cno=invoices.cno ;
UNION ALL ;
SELECT customer.cno, customer.contact, "child#2", inv2.ino, ;
inv2.idate ;
FROM customer, inv2 ;
WHERE customer.cno=inv2.cno ;
ORDER BY 1
Additional query words: VFoxMac VFoxWin FoxMac FoxDos FoxWin 2.50 2.50a multiple
Keywords: kbcode KB119354