Comma separated list in SQL

A short example of how to write a stored function that returns a comma separated list of values (Microsoft Transact-SQL):

CREATE FUNCION get_authors (@pubId int)
RETURNS nvarchar(max)
WITH EXECUTE AS CALLER AS
BEGIN DECLARE @authorList nvarchar(max);
SELECT
  @authorList = @authorList + ', '
  + authorFirstName + ' ' + authorLastName
FROM pdb_authors a, pdb_publicationAuthors b 
WHERE a.authorId = b.authorId AND b.pubId = @pubId; 
RETURN(SUBSTRING(@authorList, 3, LEN(@authorList) - 2)) END