A new question.
I have a school history table: ID_HISTORY, ID_STUDENT, ID_SCHOOL, DATE_CREATED.
When I give a date like 01/01/2007 up in the query, the query need to search the records in the school history table where the id from the students is null. And when the id is null it need to find the id from the student from a record with the same id from the school and a date that is less but higher than the other record I gave up.
I already tried to do this but with no luck. It always give me a error.
SELECT A.ID_HISTORY, A.ID_STUDENT, A.ID_SCHOOL, A.DATE_CREATED FROM SCHOOL_HISTORY A WHERE A.DATE_CREATED =
(
SELECT MAX(B.DATE_CREATED) FROM SCHOOL_HISTORY B WHERE B.ID_SCHOOL = A.ID_SCHOOL AND CAST(B.DATE_CREATED AS DATE) <= '01/01/2007' AND
(
SELECT C.ID_STUDENT FROM SCHOOL_HIST C WHERE CAST(C.DATE_CREATED AS DATE) = '01/01/2007' AND C.ID_SCHOOL = A.ID_SCHOOL
)
IS NULL
)
Sorry for my bad English
Thanks in advance
Nyh