I have a table in my database that contains all the records for a group of individuals, both male and female plus their offspring. Each record has that individuals place of birth.
I'm trying to create a cursor to display all births between a specific range of dates that show the individual's id, their date of birth and their parents. So far no problem with that
My SELECT statement is as follows
SELECT DISTINCT IdNumber,birthstate, sex, DateOfBirth, father, mother;
FROM members;
WHERE (DateOfDeath>=ldStartDate AND DateOfDeath<=ldEndDate);
ORDER BY 1;
INTO CURSOR ReportMaster
This give me exactly what I want - NOW what I want to do is pull the father and mother's birthstate from within the same file, is there a way to do it dynamically (within that same select statement)?
SELECT DISTINCT m.IdNumber,m.birthstate, m.sex, m.DateOfBirth, m.father, m.mother,
mother.birthstate, father.birthsate
FROM members m
left outer join members mother on mother.IdNumber = m.mother
left outer join members father on father.IdNumber = m.father
WHERE (m.DateOfDeath>=ldStartDate AND m.DateOfDeath<=ldEndDate)
You might be able to change the left outer join to an inner join if you know for sure you always have the father and mother.
I'm also assuming the "mother" and "father" are foreign keys to the IdNumber column in the members table.