Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL statement to combine one-to-many
Message
From
07/11/2001 14:57:14
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
 
 
To
07/11/2001 10:10:08
Bill Tetrault
Northern Trust Value Investors
West Palm Beach, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00578503
Message ID:
00578706
Views:
29
Bill

It depends whether you are using a C/S backend or local tables.

With local tables, it's easy. Create a function with foreign key as parameter, that builds the child data into a string. E.G. if your invoice primary key is iInvoice and the invoice rows are joined on thet field, you could use
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 lcString
Then you can use SQL to get what you need:

Select invoices.*,f_Getrows(invoices.iInvoice) as mString from invoices WHERE...

HTH

Regards

JR
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform