View Single Post
  #8 (permalink)  
Old 01-06-05, 10:07
Brett Kaiser Brett Kaiser is offline
SQLTeam Scrub
 
Join Date: Nov 2002
Location: Jersey
Posts: 9,976
OK...needs a little cleaning up....

Code:
CREATE FUNCTION GetAllOnLine(@id int)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Result VARCHAR(8000)

SELECT @Result = COALESCE(@Result + ', ','') + col2
FROM myTable99
WHERE col1=@id

RETURN @Result
END
GO

SELECT Col1, dbo.GetAllOnLine(Col1) FROM MyTable99
But don't you double the access paths to the table? One for the UDF and another for the SELECT? If it's a lot of rows I think mine would be more effecient...(though I still would like to know why anyone would like to do this)

Also, I don't usually like to make my UDF's some very specific, I prefer them to be as generic as possible. You could only use this for one very specific case.

Do you mind if I blog your solution as another example?
__________________
Brett
8-)

It's a Great Day for America everybody!
My Blog
My SQL Blog dbforums Yak CorralRadio 'Rita
dbForums Member List SQLTeam Member List
It's 5:00 Somewhere Pearls
The physical order of data in a database has no meaning.
Reply With Quote