I have a table Companiesdata
CREATE TABLE [dbo].[Companiesdata]
(
[Company Name] nvarchar(255),
[Industry] varchar(40),
[ParentId] int NULL,
)
and the rows are
CompanyName               Industry          Parent ID  
--------------------------------------------------------
Xyz technologies          Software             1
apple Technologies        software             1
Sun network               media                2
abc Technologies          advertising          4
PQR Technnologies         Marketing            5
abc Technologies          Media                4
I have another table
create table dbo.companiesss
(
autoid int identity(1,1),
companyname varchar(max),
Industry  varchar(max)
)
I wrote a procedure like this:
create proc pr_getlistofcompaniesss (@tparentid varchar(20))   
as 
begin
   insert into dbo.companiesss(companyname, industry) 
      select  
          [CompanyName], [Industry] 
      from 
          [Companiesdata]
      where 
          parentid in (select items from dbo.split(@tparentid,',')) 
      except
      select company name, industry 
      from dbo.companiesss 
end
The output is as below:
pr_getlistofcompaniesss 1,2,4
the rows are displayed as
AutoID    Company name              Industry
---------------------------------------------------
  1       apple Technologies        software
  2       Sun network               Media
  3       xyz Technologies          software
  4       abc Technologies          advertising
  5       abc technologies          media
instead my output should be as below:
pr_getlistofcompaniesss 1,2,4
AutoID    Company name              Industry
---------------------------------------------------
  1       apple Technologies        software
  2       Sun network               Media
  3       xyz Technologies          software
  4       abc Technologies          advertising,media
i.e if I have the same company (here abc technologies) with different industries name, then the industry field should be separated with comma displaying the record on same row i.e (advertising, media)
 
     
     
    