I have the following join, but it returns multiple instances because there are some P.ID with multiple valid instances.
But I want only the first valid instance from the first of the below joins. I've tried several methods using TOP, SELECT 1, etc., including creating a temporary table and then joining its contents. But I have had no success.
I will be very appreciative if someone can provide me with the correct syntax. Thank you.
SELECT a bunch of stuff
FROM PERSON
LEFT JOIN STPR_DATES SD
ON SUBSTRING(SD.STUDENT_PROGRAMS_ID,1,7) = P.ID
AND (SD.STPR_END_DATE IS NULL OR SD.STPR_END_DATE >= @REPORTRUNDATE)
AND SD.POS = 1
and then referenced the results of the above join in the following join and so on:
LEFT JOIN ACAD_PROGRAMS AP1
ON dbo.FIELD(SD.STUDENT_PROGRAMS_ID,'*',2) = AP1.ACAD_PROGRAMS_ID
After several other joins:
WHERE ... select criteria for P.ID