concatenating question

  • Just a quick question about concatenating.

    I need the results from the User Role row to be concatenated.

    Is there a way that I can do this if the results are coming from one column on a table?

    I was able to do this with the Colleague row as I was pulling from two different columns on a table.

    What it's pulling now:

    BUColleague User Role

    1234Pollard, RobertGrocery Manager

    1234Pollard, RobertProduce Manager

    What I want it to look like:

    BUColleague User Role

    1234Pollard, RobertGrocery Manager, Produce Manager

    Any advice?

    Thanks!

  • Here's a sample concat script. I can't adapt it for you needs without table structure and sample data.

    SELECT

    T.name,

    STUFF((

    SELECT

    ',' + name

    FROM

    sys.columns C

    WHERE C.object_id = T.object_id

    ORDER BY

    name

    FOR

    XML PATH('')

    ) , 1 , 1 , '') As Columns_

    FROM sys.tables T

    ORDER BY name

  • Thanks! I'll see what I can do with this.

  • What specific version of SQL Server are you using?

    SELECT 'ProductVersion', SERVERPROPERTY('ProductVersion')

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Microsoft SQL server 2005

  • Right...but what is the result of the query I posted on your instance?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Ah, I'm not around my computer at the moment. I'll have to run this in the morning. I will get back to you with the results.

    So I'm assuming it is possible to concatenate within a column? I feel as though I've tried everything and it still doesn't work lol I have tried looking for another table but I can't find one.

    Thanks!

    Jessica

Viewing 7 posts - 1 through 6 (of 6 total)

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