Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UDF - Return on distict listing
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01060504
Message ID:
01060562
Views:
7
This message has been marked as a message which has helped to the initial question of the thread.
Try
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.
>
>Hope someone can help with this.
>
>Kirk
>
>
>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
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform