title: Return comma-separated list from SQL Server
body: <p>I have a stored procedure as below. Now I want to modify it so that it returns the value as a comma separated list. </p>
  
  <pre><code>CREATE PROCEDURE [dbo].[CUST_Notification_GetCompaniesFromEmails]
       @EmailValue AS NTEXT
  AS
       SELECT DISTINCT 
           ISNULL(CompanyAddressesContacts.FirstName, '') + ' ' +  
           ISNULL(CompanyAddressesContacts.LastName, '') AS ContactName
           ,ISNULL(dbo.Companies.CompanyName,'') AS CompanyName,
           CASE
              WHEN CompanyName = 'Meraas Development' THEN '1'
              WHEN CompanyName = 'Samsung C&amp;T' THEN '2'
              ELSE '3'
           END AS id
       FROM 
           dbo.CompanyAddressesContacts
       INNER JOIN 
           dbo.Companies ON dbo.CompanyAddressesContacts.CompanyId = Companies.Id
       WHERE 
           dbo.CompanyAddressesContacts.Email IN 
              (SELECT [value] 
               FROM dbo.SplitWords(@EmailValue,';'))
  </code></pre>
  
  <p>The above code returns values as a normal select statement would do . Now I want a modification in the code so that it returns a value as comma-separated list.</p>
  
  <p>Thanks!</p>