Question

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)?

Was it helpful?

Solution

    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.

OTHER TIPS

@aquinas, This is not a good syntax for VFP. You have used m. as a local alias! It should be m.ldStartDate and m.ldEndDate but having rest of the m. in that query is simply an invitation to error (logical error, one may go unnoticed or show as error only if you are lucky).

Please reserve m. for memory variables. mdot working this way in this query is only a bug that would never be corrected.

PS: If you are an experienced developer then it may not bite you. However, I would think the owner of question as beginner/intermediate and she/he shouldn't learn it this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top