PIVOT/UNPIVOT Question

  • Hi ,

    I have a req as follows:

    My table structure is something like below:

    TestIDDistinctionFirstSecond

    10185%60%50%

    10250%85%NULL

    10350%60%85%

    I want my result as following:

    TestID50%60%85%

    101SecondFirstDistinction

    102DistinctionNULLFirst

    103DistinctionFirstSecond

    Appreciate your help.

  • sqlzealot-81 (7/10/2012)


    Hi ,

    I have a req as follows:

    My table structure is something like below:

    TestIDDistinctionFirstSecond

    10185%60%50%

    10250%85%NULL

    10350%60%85%

    I want my result as following:

    TestID50%60%85%

    101SecondFirstDistinction

    102DistinctionNULLFirst

    103DistinctionFirstSecond

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

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