Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Related Tables Question
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00248316
Message ID:
00248325
Views:
12
>>Just wondering something. I have a classic parent child one to many relationship, Lets just say an Invoice has many detail items. Is there a way to SEEK() for something in the parent table, select the related child table, then go to the last record for that Parent table record? When I do this I get the actual last record in the child table not the last child record for the related parent record. Is the only way to do this sort of thing with a SELECT-SQL or am I missing something
>>
>>Much Thanks
>
>Usually, SET ORDER TO INVOICE DESC in the child table will list the last item first if, from the parent table, you SET RELATION TO INVOICE INTO CHILDTABLE.

Sorry, that is a little misleading. This is not conditional on setting the relation. If you set the relation and go to an invoice in the Invoices table, the record pointer in the child table will go to the first matching detail item for that invoice. This will, in this case, be the last item added.

A more elegant method would be to create a parameterized view of the detail items table --

create sql view v_DetailItems as select * from DetailItemsTable where Invoice = ?nInvoice order by KeyID desc

The above is code similar to what the View Designer would generate and assumes KeyID is the PK field in the DetailItemsTable. Then in your form, you can use this view just like a table.

Use v_DetailItems nodata

Then whenever the Invoice number changes:

local nInvoice
nInvoice = Invoices.Invoice
requery("v_DetailItems")

You can make the view updatable as well.
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform