Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SET RELATION
Message
From
25/08/1998 11:18:22
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
25/08/1998 11:07:52
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00129719
Message ID:
00129725
Views:
19
>>>I have a parent table P2 and two related child tables C1 and C2.
>>>Each table has in excess of 1 million records. After SETting
>>>the RELATIONs, how can I examine only those records in the
>>>children tables that should be constrained to the parent relationship?
>>>
>>>Based on the child related info, I will update a field in the
>>>parent table.
>>Create a form with 3 grids. Set recordsources as P2, C1 and C2. In C* set linkmaster, childorder, relationalexpression. You're done.
>>Cetin
>
>I do not want to use a gird or any type of interface. The relations
>have been set - no problem there. As I SCAN each parent record I want
>to examine just the results of the children records and based on that
>info update a field in the parent. For example, how do I know the
>total number of records in child table one (C1)? How can I run a
>query or a simple COUNT in the child that is constrained to the
>matching parent record? A simple SUM was going through ALL records
>in the child.
select parent
scan
  nCnt1 = countchild("c1",parent.matchid1,"matchfield1")
  nCnt2 = countchild("c2",parent.matchid2,"matchfield2")
  nSum1 = sumchild("c1",parent.matchid1,"matchfield1")
  nSum2 = sumchild("c2",parent.matchid2,"matchfield2")
* Some work
endscan

function countchild
lparameters tcTableName, tcParId, tcChildKeyField
select cnt(*) from (tcTableName) ;
  where &tcChildKeyField = tcParId ;
  into array aCnt
return iif(type("aCnt")="N",aCnt[1],0)

function sumchild
lparameters tcTableName, tcParId, tcChildKeyField, tcExp2sum
select sum(&tcExp2sum) from (tcTableName) ;
  where &tcChildKeyField = tcParId ;
  into array aSum
return iif(type("aSum")="N",aSum[1],0)
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
Previous
Reply
Map
View

Click here to load this message in the networking platform