Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Notes in the same row
Message
From
15/04/2007 05:34:06
 
 
To
10/04/2007 16:22:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01214141
Message ID:
01216018
Views:
21
This message has been marked as the solution to the initial question of the thread.
Hello Samuel,

I did not read the whol thread, but it seems the problem is not yet solved.

Do I understand correctly? You have two tables 1:n related, you want each parent records note field to contain the concatenation of the notes of each child record.

A correlated UPDATE-SQL is not capable to do that. Also with a group by you don't have an aggregation function that could concatenate child record notes.

Take a look at this example, it generates it's sample data, then aggregates "notes":
* creating some sample data
Create Cursor curParent (iid I, mNote M)
Create Cursor curChild (iid I, cNote C(200))
Index On iid Tag xid

For I = 1 To 20
   Insert Into curParent Values (I,"")
   For j=1 To Rand()*20+1
      Insert Into curChild Values (I, Chr(64+j))
   Endfor j
Endfor I

* updating parent records
Select curParent
Scan
   lcNotes= ""
   Select curChild
   If Seek(curParent.iid,"curChild","xid")
      Scan Rest While curParent.iid = curChild.iid
         lcNotes = lcNotes + Alltrim(curChild.cNote) + " "
      Endscan
      Replace mNote With lcNotes In curParent
   Endif
Endscan
Does that help you see the needed ingredients? a) An index in the child table, with which you can find the child records related to a parent record. b) two nested scan loops.

In fact you can also do without an index, but it would be much slower then:
* ...
* updating parent records
Select curParent
Scan
   lcNotes= ""
   Select curChild
   Scan For curParent.iid = curChild.iid
      lcNotes = lcNotes + Alltrim(curChild.cNote) + " "
   Endscan
   Replace mNote With lcNotes In curParent
Endscan
Bye, Olaf.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform