My big select is below... basically I need a trick! the bit below will fail because when it finds a null, the = ssh.end_date won't match (I need an "ssh.end_date is null") or similar. How can I do this?? Full select at the bottom. I want the null records first then afterwards the highest end date. EVERYTHING ELSE WORKS! Thanks! Tim-- null end_date first then max history record.inner join ( select max(isnull(end_date,'2076-06-06 00:00:00')) [end_date], person_id -- This gets the latest school history record. from sims.stud_school_history ssh2 group by person_id ) x2 on x2.person_id = ssh.person_id and case x2.end_date when '2076-06-06 00:00:00' then null else x2.end_date end = ssh.end_date
update s set latest_adno = Nullfrom sims.stud_student sinner join sims.stud_school_history sshon ssh.person_id = s.person_idinner join sims.ra_applicant aon s.person_id = a.person_idinner join sims.ra_application appon app.applicant_id = a.person_idinner join sims.ra_application_status_history apphon apph.application_id = app.application_idinner join sims.ra_application_status appson apps.lookup_value_id = apph.application_status_idinner join sims.ra_application_status_category appscon appsc.category_id = apps.category_idinner join (select max(transition_date) [transition_date], application_id -- This gets the latest application status. from sims.ra_application_status_history apph2 group by application_id ) x on x.application_id = apph.application_id and x.transition_date = apph.transition_date-- null end_date first then max history record.inner join ( select max(isnull(end_date,'2076-06-06 00:00:00')) [end_date], person_id -- This gets the latest school history record. from sims.stud_school_history ssh2 group by person_id ) x2 on x2.person_id = ssh.person_id and case x2.end_date when '2076-06-06 00:00:00' then null else x2.end_date end = ssh.end_datewhere appsc.code != 'Admitted'