I have a number of tables across two databases that I would like to pulll information out of to display in a grid in a web page.
If I run the following sql it works fine and only returns one row:
Select DISTINCT s.STUDENT#, s.SURNAME,s.GIVEN_NAME,ar.EN_EMAIL,ar.CAREGIVER_NO,i.GIVENNAME,i.SURNAME,i.EMAIL,i.EMAIL_BILLING,ax.CORR_PREFERENCE
from
[PCSchool].[dbo].[STUDENT] s
INNER JOIN [PCSchool].[dbo].[ALUMREL] ar
on s.STUDENT# = ar.CHILD#
LEFT JOIN
[PCSchool].[dbo].[IDENTITY] i
on ar.PARENT# = i.[MEMBER#]
left join [PCSchool].[dbo].[ALUMREL_EX] ax
on ar.parent# = ax.PARENT#
where (ar.PARENT# <> ar.FAMILY_HASH) and ax.CORR_PREFERENCE = 1 and ar.EN_EMAIL = 'I' where s.STUDENT#=7282)
What my problem is, I have another table that has a list of students that has a counter in it and a detention type.
I want to be able to pull the above email information from one table based on the Detention table. The StudentCode in the detention table and the Student# in the above table are the same for each student.
I have no idea whether this can be done with SQL or whether I need to do it via server side code.

