Home Forums SQL Server 2005 T-SQL (SS2K5) How to Build a single row with groups of fields from several rows per key RE: How to Build a single row with groups of fields from several rows per key

  • Avraham de-Haan (10/6/2012)


    It is just an example, my data is more complicated.

    Actually I have from 0 to 15 data/trailer rows (like orders) for each customer.

    Now I need to send the customer data _including_ all it's order/trailers in 1 single (long) row.

    My example imitates these "order" rows which I need to combine into up to 15 "groups" of fields in the output row and glue them to each customer data.

    I hope I clarified myself.

    Thanks

    Yep.... knew it was just example data and that's why I asked for a bit more detail.

    So, each group will have 3 entries (or less as in your example) and each customer can have up to 15 groups. Got that.

    0. I'm assuming that the data-type in the original table for the 3 entries for each group is INT. Is that correct?

    1. What do you want to return for a customer with 0 groups and how will that be manifested in the original table.

    2. Also, since you're sending this to a customer and it sounds a whole lot like they're going to be importing the data either into a spreadsheet or a table, what do you want for delimiters between the "columns" of data in the output? Commas? Tabs? or ...

    3. ... or do you want this to be a fixed field format? If so, what are the data-types in the 3 values of each group in the original table? Need to know this to be able to handle the max width.

    Also, since you're kind of new on this forum, please take a look at the article at the first link in my signature line below. Posting readily consumable data (even if it's just example data) like that would make it so we didn't have to ask so many questions to help you. Thanks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)