Unpivoting (?) a data set.

  • If I have a data set which looks like this:

    Field Name...FieldA...FieldB...FieldC

    Count..........132........2.......432

    And I want this:

    FieldA 132

    FieldB 2

    FieldC 432

    The number of Fields would be dynamic as they are fields in a table.

    What's the best way to accomplish this?

  • UNPIVOT it is 🙂

  • What exactly do you mean when you say the fields would be dynamic? You can't dynamically set up field names in Pivot or UnPivot... they need to be defined.

    UNPIVOT is the TSQL command that you want to research.

  • The fields are the fields in a table. Each table has different fields. This data set represents the count of distinct values per field.

    Therefore, I need a way to "unpivot" this dynamically.

  • I know what you are up to and i have a code for that, but i have limited time to set-up sample data and create a query for that

    Can you please some data according the specifications here: http://www.sqlservercentral.com/articles/Best+Practices/61537/ , once you do, i shall provide u the script to run for that sample data.

  • Thanks for the ideas folks. I re-wrote it to return the normalized data set instead.

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

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