FUNCTION f_GetRows(liInvoice) *---Receives invoice key as parameter, builds string based on invoice rows LOCAL lcString,lxSelect *---Save currently selected table so we can restore lxSelect=SELECT() *---Get the invoice rows for the selected invoice SELECT * FROM invoiceRows WHERE iInvoice=?liInvoice ORDER BY iRowNumber INTO CURSOR c_InvoiceRows *---Build the String lcString="" SCAN lcString=lcString+... ... ENDSCAN *---Restore selected table SELECT (lxSelect) *---Make sure string>255 characters so it will be a memo field in SQL IF LEN(lcString)<255 lcString=PADR(lcString,255) ENDIF RETURN lcStringThen you can use SQL to get what you need: