Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL statement to combine one-to-many
Message
De
08/11/2001 06:14:46
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
07/11/2001 14:57:14
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., Nouvelle Zélande
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00578503
Message ID:
00578937
Vues:
24
>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

John,
Are you sure making string longer than 255 would make it a memo in SQL ?
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform