General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Creating a Cursor from 2 tables, related or not
Hello all,
I want to create a cursor with information about defendants, victims and defendant-victim relationships, if any, for a case.
The tables involved are:
defendants w/primary key DefID (and tags caseID and PersonID)
victims w/primary key VictimID (and tags caseID and PersonID)
people w/primary key PersonID
vicRelations with foreign keys DefID and VictimID (and RelationID tag)
RelationDescriptions w/primary key RelationID
Victims and defendants in a case may not be related, or they may have one or more relationships (example, "brother", "employer"). If there is no relationship, I still want to display the victim, w/a blank relationship.
I want to create a cursor, to display in a grid, that is linked to a master by DefID.
Ideally, I would do this in a view, but it seems too involved. What I've done is:
1. created a cursor, cDisplayVictims ( VictimName C(57), Relation C(20), DefID I ) to display the result.
2. Select all the relations for the defendants in the case into a cursor, cTempRelations, then create an INDEX ON ALLTRIM( STR( DefID ) ) + ALLTRIM( STR( VictimsID ) ) Tag DefID [is there a better way to create a tag on 2 integer fields?]
3. Select victim and defendant info, into a cursor, cTempVictims, with one record for each possible victim-defendant combination (victim name, victimID, DefID), then SET RELATION TO ALLTRIM( STR( DefID ) ) + ALLTRIM( STR( VictimsID ) ) INTO cTempRelations
4. Scan cTempVictims, inserting records into cDisplayVictims - if no records in cTempRelations, insert a record w/a blank relation, otherwise, insert one record for each relation in cTempRelations.
And it works...but, is there a simplier/more elegant method?
TIA for any input...J
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only