Pivot I guess

  • I have one table of data with Stock Number, Code, Specs. There are several entries per stock number. I would like to get the stock number then all of the specs combined into one field. Here are the results for one stock number. Is there any way to get this where I can get all of the results (specs) combined into one single field?

    ID Stock Code Specs

    1 1651566125 1 COFFEE, FOR 12 CUP POUR-OVER TYPE COFFEE BREWER. FILTER

    2 1651566125 3 TO BE BLEACHED PAPER TOWELING. FILTER BOTTOM TO BE NO

    3 1651566125 5 LESS THAN 3-1/8 INCHES WIDE AND NO MORE THAN ....

    [font="Tahoma"]
    --SQLFRNDZ[/url]
    [/font]

  • No one have any Idea .....

    I appreciate your answers.

    [font="Tahoma"]
    --SQLFRNDZ[/url]
    [/font]

  • Serial/Quirky update in a temp table, a while loop, or possibly a recursion cte. I don't have time right now to convert your data into a usable test structure.

    If you check the first link in my sig in setting up test data you'll most likely get better results, and the code will be tested, to boot.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Pavan as Craig says, please set up some sample data in the form of a CREATE TABLE statement followed by INSERT to populate your table with data. Include at least two partitions (separate ranges) to show that the technique works. Your requirement is common and trivial, proving the solution works is not. All of your data would be ideal but a representative sample is sufficient. Thanks.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • I guess what Chris refers to is the FOR XML PATH() concept.

    You might find a suitable solution by searching for "string concatenate for xml path" on either this forum or the web.

    The "tricky part" (more or less) is to defiine the order the different specs need to be shown.

    that's why (I guess) Chris asking your for the sample data.

    And I second Chris: provide ready to use sample data, the business rule(s) and your expected result and there will be a number of people willing to help you.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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