/* DummyFamily-Add.sql
Based on trick developed by Jerry Bryan to cause Narrative Descendant reports
to output childless, spouseless children in their own generation, along with their 
married or parental siblings.

Adds dummy family(ies) for this(all such) child(ren), based on the runtime parameter,
to the FamilyTable. Requires SQLite Export Personal or equiv to support selection of a single
child.

After completing the report, run DummyFamily-Delete.sql; it is probably less risky, however,
to run the first query and report on a copy of the database and then delete the copy.
2012-01-15 ve3meo
*/
 
INSERT INTO FamilyTable 
 (FatherID)
SELECT ChildTable.ChildID FROM ChildTable
WHERE
 CASE 
  WHEN @RIN NOT LIKE '' THEN ChildTable.ChildID = @RIN
  ELSE 1
 END 
AND
 ChildTable.ChildID NOT IN (SELECT FatherID FROM FamilyTable) 
AND
 ChildTable.ChildID NOT IN (SELECT MotherID FROM FamilyTable)
; 
