SQL Script for combine string using 2 tables

  • Hi

    I have two tables - OrderHeader and OrderDetail

    Each table has an OrderNumber field. This also is the link to join them.

    Each OrderDetail table also has a LineNumber table.

    Each table has a field called Description.

    There could be info in either Description field on the header or the line level.

    I need to run SQL against these tables which will cause the Order Header's Descriuption to end up with the OrderHeader's Description set to the original contents of that field, followed by the concatenation of all of the descriptions (in any order) for the associated detail lines.

    for example, there is an order number 3

    Order number 3 has in the OrderHeader.Description the entry of "OrderLevelInfo".

    Order number 3 has two detail records with their OrderNumber set to 3. One of the Descriptions is set to ABC and the other record is set to DEF.

    I need an SQL script which will cause the OrderHeader.Description to be set to "OrderLevelInfo ABC DEF".

    How do I do that?

    Please help.

    Thx

    Regards

    Vijji

  • Vijji-429978

    You will get tested assistance if you post the table definitions, some sample data and what you have attempted. Following the suggestions contained in the first link of my signature block.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • While we're waiting for a bit of readily consumable test data, I have to ask... WHY? What is the business reason that requires this type of denormalization? I ask because I'm not only curious but sometimes there's a better way depending on the business reason for the requirement.

    --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)

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

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