Need to store more then two ids in single column

  • Hi Sir,

    I have a requirement to store if one main id have more then two child ids in single column like

    If main id is 1234 and it has two child ids like 2222 and 3333 then output should be in single row instead of two or more rows.

    Current result is,

    Main ID Child_ID

    1234 2222

    1234 3333

    Expected Result should be,

    Main ID Child_ID

    1234 2222,3333

    Table script,

    CREATE TABLE MAIN

    (main_id INT,

    child_id INT)

    INSERT INTO MAIN VALUES (1234,2222);

    INSERT INTO MAIN VALUES (1234,3333)

  • I would investigate the use of "FOR XML PATH".

    We use it regularly to do exactly what you want to do (albeit with different values and for different reasons).

    It's extremely fast (although there may be better ways).

  • Thanks, but How i can do this for INT datatypes?

    Please suggest me.

  • Please don't post the same question in multiple forums. It leads to all sorts of confusion. I've answered your question over here. I'd suggest we focus all the conversation there.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Closing. Visit the other thread for an answer.

Viewing 5 posts - 1 through 4 (of 4 total)

The topic ‘Need to store more then two ids in single column’ is closed to new replies.