How can I get multiple alert records (up to 10 per student) to appear on one record per student? I'm attempting to use row number to number the records and then place them in the output, but the code I have written does not work due to incorrect syntax errors on the "where" parameter in the cross apply statement. I've tried multiple ways to accomplish what I need, but can't get past the errors. Please help.
select
sd.[student_number],
a.[health_alert],
a.[comments],
b.[health_alert],
b.[comments]
from student_enrollmentcube as se,
student_demographicscube as sd
cross apply (select a.[health_alert], a.[comments], (select row_number()
over (partition by a.[student_id] order by a.[student_id]) as r1 from
ar_student_health_alerts) a) where a.[student_id] = sd.[student_id] and
r1 = 1)
cross apply (select b.[health_alert], b.[comments], (select row_number()
over (partition by b.[student_id] order by b.[student_id]) as r2 from
ar_student_health_alerts) b) where b.[student_id] = sd.[student_id] and
r2 = 2)
where se.student_id = sd.student_id and
se.enrollment_status= 'active' and
se.[current_academic_year] = 'y'