Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to combine 3 child records into 1 record
Message
 
To
16/12/1999 16:58:15
Shane Gilbert
Oklahoma State Department of Education
Norman, Oklahoma, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00304928
Message ID:
00305087
Views:
22
Shane,

You can use SQL to do this.

Run the code below (you may need to fix the line continuation stuff:

-- Start Runnable Code --

create cursor parent1 (ParentID I)
create cursor child1 (ParentID I, Field1 C(5), Field2 C(5), Field3 C(5), Field4 C(5))
create cursor child2 (ParentID I, Field1 C(5), Field2 C(5), Field3 C(5), Field4 C(5))
create cursor child3 (ParentID I, Field1 C(5), Field2 C(5), Field3 C(5), Field4 C(5))

for i = 1 to 5
insert into parent1 values (i)
insert into child1 values (i, '11-' + tran(i), '12-' + tran(i), '13-' + tran(i), '14-' + tran(i))
insert into child2 values (i, '21-' + tran(i), '22-' + tran(i), '23-' + tran(i), '24-' + tran(i))
insert into child3 values (i, '31-' + tran(i), '32-' + tran(i), '33-' + tran(i), '34-' + tran(i))
endfor


select parent1.ParentID, ;
child1.field1 as c1f1, ;
child1.field2 as c1f2, ;
child1.field3 as c1f3, ;
child1.field4 as c1f4, ;
child2.field1 as c2f1, ;
child2.field2 as c2f2, ;
child2.field3 as c2f3, ;
child2.field4 as c2f4, ;
child3.field1 as c3f1, ;
child3.field2 as c3f2, ;
child3.field3 as c3f3, ;
child3.field4 as c3f4 ;
FROM parent1 ;
inner join child1 on parent1.parentID = child1.parentID ;
inner join child2 on parent1.parentID = child2.parentID ;
inner join child3 on parent1.parentID = child3.parentID ;
into cursor joinresult


-- End Runnable Code --

Now have a look at (browse) the joinresult cursor

The select statement's the key, the rest of it's just setting up for this example.

HTH

Cheers,

Andrew


>I have a parent table that has three child records related to it. I need to grab a field from the parent table and four fields from each of the child records into ONE record(it will have 13 fields, one from the parent and 4 from each of the child records). I think it should be some type of UNION, but I can't figure it out. Any help would be greatly appreciated.
>
>
>Shane


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Previous
Reply
Map
View

Click here to load this message in the networking platform