Concatenating records not fields

  • is there a way to concat the records remeber not fields

    example like list of users from a table  separated by - or , (waqar-geir-key -hans etc)

  • If you are attempting to create a delimited list of values from the same column but different rows, take a look at "coalesce".  Here is a simple example that concatenates ChildIDs for a specific ParentID:

    create table RelationshipTable (ParentID NUMERIC, ChildID NUMERIC)

    -- insert some data into RelationshipTable

    declare @MemberList VARCHAR(7000)

    SELECT @MemberList = COALESCE(@MemberList + ',', '') + RTRIM(ChildID)            FROM RelationshipTable WHERE ParentID = 12345

    Hope this helps

    Wayne

     

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

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