help on SQL

  • I have two tables , the schema is attached.

    I would like to get the result as the second attachment.

  • Now, show us what you have done so far in an attempt to solve your problem.

  • This?

    SELECT P.Product_id , CrsApp.Item , PD.description

    FROM Product P

    CROSS APPLY dbo.DelimitedSplit8K (P.Category , ',') CrsApp

    JOIN Prod_desc PD

    ON CrsApp.Item = PD.Category

    ORDER BY CrsApp.Item ,P.Product_id , PD.description

    And the code for dbo.DelimitedSplit8K is here --> Tally OH! An Improved SQL 8K β€œCSV Splitter” Function[/url]

    Edit : Added the link to DelimitedSplit8K

    Edit 2: Changed the ORDER BY order

  • I wish I have created the tables.

    But the tables have already existing there like that given to us, I just help with a query.

    I cannot change the table structure in this case.

    If I could, I wouldn't have posted the message

  • Thank you, ColdCoffee,

    It works perfectly.

    The function seems a very useful one

  • CELKO (5/1/2012)


    Here is what you should have posted.

    If you had bothered to look, the op posted some pretty good code for the post including sample data. πŸ˜›

    Now do a simple join. In the future, please post code and not pictures.

    Agreed but that's only a part of the problem posted. Let's see your solution to normalize the requiest, please. πŸ˜‰

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

  • sqlfriends (5/1/2012)


    Thank you, ColdCoffee,

    It works perfectly.

    The function seems a very useful one

    Please forward your thanks to the poster above me, who invented it πŸ˜€

    And the previous poster is ----> Jeff πŸ™‚

  • Thank you a million, Jeff.

  • Thank you both for the feedback. CC, well done and well played. Team effort here. πŸ™‚

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

  • sqlfriends (5/1/2012)


    I have two tables , the schema is attached. I would like to get the result as the second attachment.

    Why do you have comma separated values in your database?

Viewing 10 posts - 1 through 10 (of 10 total)

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