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?