/dev/null

Static is evil.

October 6, 2007

Comma separated list in SQL

Tags: — 06:42

Just 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

1 Comment »

  1. I want to host an online Poker Game, and i want to sell usernames and passwords where customers can buy them?

    Comment by VPS and dedicated servers — September 4, 2011 @ 04:17

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by PHP, Memcached, Suhosin, MySQL and WordPress