Trying To Do an UNPIVOT But Not Sure If I need To

  • I really need help not sure if it requires an UNPIVOT which I'm trying to figure out how to write that one in a query or some other method.

    I don't have any code for an example but I do have sample data to try and show what it is I'm doing in SQL.

    Original Data Layout header Example:

    client_name | brand_name | client_id | brand_id

    This is the data I'm working with and below the example is how I want to lay it out.

    UNPIVOT or whatever way it takes in SQL, Example:

    client_name | client_id | brand_id | brand_name1 | brand_name2 | brand_name3

    I only listed the headers for the columns

    Someone please help I'm pulling my hair out on this, thanks to all who can help.

  • If you have a fixed number of brand_names then you could either use PIVOT (see BOL, aka BooksOnLine, the SQL Server help system), or CrossTab (see the related link in my signature). If the number of brand_names can vyry, you should look into the DynamicCrossTab link.



    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 2 posts - 1 through 1 (of 1 total)

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