select @returnValue = @returnValue+rtrim(Surgeon)+'; ' FROM ( select DISTINCT Surgeon from dbo.meetings mx inner join dbo.meetproc mp on mp.meetingnumber=mx.meetingnumber where mx.meetingnumber = @tiMeetID order by mp.sysorder ) dt1>In the UDF below, I return a ; seperated list of surgeons assigned to a case. Each case is represented by a meeting record, and 1 or more child records in the meetproc table. This function works...BUT. A surgeon is stored in the meetproc table, if there are two procedures (2 meetproc records) associated with the case, the same surgeon might be assigned to both. In that case, I only want to return his name once. If there are two different ones, then I want to return both of them.
>CREATE FUNCTION Get_All_SurgeonsOnCase (@tiMeetID int) >RETURNS varchar(1000) AS >BEGIN > Declare @returnValue varchar(1000) > set @returnValue=' ' > select @returnValue = @returnValue+rtrim(Surgeon)+'; ' > > from dbo.meetings mx inner join > dbo.meetproc mp on mp.meetingnumber=mx.meetingnumber > where mx.meetingNumber = @tiMeetID > order by mp.sysorder > declare @tiLen int > set @tiLen=len(@returnValue) > > if (@tiLen > 0) > begin > set @returnvalue=substring(@returnValue,1,@tiLen-1) > end > set @returnValue=ltrim(@returnValue) > return (@returnValue) >END > >