Change row to column

  • Greetings all.

    I am attempting to change the way a dataset is viewed. Long story short, I need to take a row and convert it to a column.

    Here is what I have now in my data. This continues on a 24 hour loop:

    Date/Time TagValue

    2/18/15_0:00:0700.6049639

    2/18/15_0:00:071-0.1630784

    2/18/15_0:00:0720.3

    2/18/15_0:00:073-0.2689363

    2/18/15_0:00:1700.5247266

    2/18/15_0:00:1711.43E-02

    2/18/15_0:00:1720.3

    2/18/15_0:00:1730.0915528

    I have a date/time that repeats 4 times for each record, with a recurring tag and a corresponding value. I want to pull it in to view like this instead:

    Date/Time Tag 0 Tag 1 Tag 2 Tag 3

    2/18/15_0:00:07 0.6049639 -0.1630784 0.3 -0.2689363

    2/18/15_0:00:17 0.5247266 1.43E-02 0.3 0.0915528

    Any ideas if this is even possible?

    Thanks,

    CJ

  • Read the following article regarding CROSS TABS. [/url]

    This is an example on how to do it.

    SELECT [Date/Time],

    MAX( CASE WHEN Tag = 0 THEN Value END) Tag0,

    MAX( CASE WHEN Tag = 1 THEN Value END) Tag1

    FROM MyTable

    GROUP BY [Date/Time]

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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