Trouble formatting data from table.

  • Hello,

     

    I am trying to format data in a specific way from one table.   The columns look like this currently:

    CustomerIDData EntryEntry NumberReportDate
    A00AA033Entry106-Mar-2019 12:24:49
    A00AA033Task106-Mar-2019 13:47:53
    A00AA033Task213-Mar-2019 18:21:41
    A00AA033Entry219-Mar-2019 10:24:45
    A00AA033Entry302-Apr-2019 11:14:00
    A00AA033Entry416-Apr-2019 10:54:39
    A00AA033Task324-Apr-2019 20:35:32
    A00AA033Entry530-Apr-2019 12:16:06
    A00AA033Task408-May-2019 18:03:02


    CustomerIDData EntryEntry NumberReportDateAssoc DataEntry NumberReportDate
    A00AA033Entry106-Mar-2019 12:24:49Task106-Mar-2019 13:47:53
    A00AA033Entry219-Mar-2019 10:24:45Task213-Mar-2019 18:21:41
    A00AA033Entry302-Apr-2019 11:14:00NULLNULLNULL
    A00AA033Entry416-Apr-2019 10:54:39Task324-Apr-2019 20:35:32
    A00AA033Entry530-Apr-2019 12:16:06Task408-May-2019 18:03:02

    Hoping someone might be able to help me get the columns formatted this way as I have tried multiple methods, each failing to get it to where I want it.

  • potentially something similar to this

    select customerid
    , max(case when [Data Entry] = 'entry' then [Data Entry] else null end) as [Data Entry]
    , [Entry Number]
    , max(case when [Data Entry] = 'entry' then ReportDate else null end) as ReportDate
    .. repeat for "task"
    from tablename
    group by CustomerID
    , [Entry Number]
  • What is the association between an Entry and a Task?  It is obviously not the entry number - nor does it appear to be related to the report date...but there must be some relationship.

    How do you identify that the task with entry number 2 with a report date of 13-March is associated with the entry with an entry number of 2 and a report date of 19-March.

    How do you identify that the task with the entry number 3 with a report date of 24-April is associated to the entry with the entry number 4 with a report date of 16-April?

    And why is the entry with entry number 3 not associated with the task with entry number 3?

    The logic doesn't seem to match up...

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

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

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