PIVOT/UNPIVOT Question

  • Hi ,

    I have a req as follows:

    My table structure is something like below:

    TestID Distinction First Second

    101 85% 60% 50%

    102 50% 85% NULL

    103 50% 60% 85%

    I want my result as following:

    TestID 50% 60% 85%

    101 Second First Distinction

    102 Distinction NULL First

    103 Distinction First Second

    Appreciate your help.

  • sqlzealot-81 (7/10/2012)


    Hi ,

    I have a req as follows:

    My table structure is something like below:

    TestID Distinction First Second

    101 85% 60% 50%

    102 50% 85% NULL

    103 50% 60% 85%

    I want my result as following:

    TestID 50% 60% 85%

    101 Second First Distinction

    102 Distinction NULL First

    103 Distinction First Second

    Appreciate your help.

    DDL and DML?

    CREATE TABLE #Sample (TestID ...

    INSERT INTO #Sample ...

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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