SQL Server Performance

Stored procedure help

Discussion in 'ALL SQL SERVER QUESTIONS' started by Tsaliki, Aug 8, 2012.

  1. Tsaliki New Member

    i have a table Companiesdata

    CREATE TABLE [dbo].[Companiesdata]
    (
    [Company Name] nvarchar(255),
    [Industry] varchar(40),
    [ParentId] int NULL,
    )


    the records 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 other table

    create table dbo.companiesss
    (
    autoid int identity(1,1),
    companyname varchar(max),
    Industry varchar(max)
    )


    i wrote a procedure as below:

    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 records 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 seperated with comma displaying the record on same row i.e ( advertising,media)


  2. FrankKalis Moderator

Share This Page