Concatenate column across multiple rows

  • Hi,

    I am having a problem where in i want to concatenate the values of a field across multiple rows for a given set of primary keys. To illustrate, consider the temporary table #TEMP being used in a stored procedure:

    EmpNo Dept  Tech   ConcatField

    1        CS     vb

    2        ecom  java

    1        ecom  java

    1        Cs      pb

    2        ecom  asp

    3        mf      cobol

    1        cs      oracle

    here for a combination of empno n dept fields i want a concatenated string which will have the TECH field values separated by a comma.

    so now the concat field should be :

    EmpNo Dept Tech   ConcatField

    1      CS      vb         vb,pb,oracle

    2      ecom   java     java,asp

    1     ecom   java     java

    1     Cs       pb         vb,pb,oracle

    2     ecom  asp      java,asp

    3     mf      cobol     cobol

    1     cs       oracle    vb,pb,oracle

    I am advised not to use cursors.

    Looking out for a solution.

    Thanks,

    Sairam

     

  • Hi Sairam,

    I think that the problem is similar to this one.

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=5&messageid=99869

    Regards,

    Goce Smilevski.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply