3

I would like to take the data output from the query below and join all of the email addresses together separated by a semicolon grouped by the employee name.

SELECT
    DISTINCT
    p.email
    , e.name 
FROM
    PERSON p
INNER JOIN 
    EMPLOYEE e
ON 
    p.agentofrecord_id = e.employee_id 
WHERE 
    dbo.GetPersonMember(p.person_id) = 1
    AND (p.isactive = 1)
    AND p.email <> ''
ORDER BY name
RSolberg
  • 26,821
  • 23
  • 116
  • 160
  • You are asking how to violate 1NF, which SQL isn't really designed to do e.g. the SQL Standard lacks a 'Concatenate' set function. http://en.wikipedia.org/wiki/First_normal_form#Domains_and_values. – onedaywhen Jun 18 '09 at 07:24
  • @onedaywhen - This is to get email addresses in a usable format grouped by employee... Nothing else... If I wasn't doing it here, it'd be code or excel... Just looking for something easy to save some time later. – RSolberg Jun 18 '09 at 15:12
  • See [http://stackoverflow.com/questions/905818/tsql-comma-separation/913023#913023](http://stackoverflow.com/questions/905818/tsql-comma-separation/913023#913023) – van Jun 18 '09 at 05:08

1 Answers1

5

Basically, it looks like you want MySql's GROUP_CONCAT aggregate function in TSQL. If that's the case, this article may help -- check it out!

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395