I'm looking to transpose a temp table (`Result` column is of `DATETIME` datatype) below to aggregate records based on `MeasureDSC` values (make two new columns: `First` and `Next`). 

I'm using Microsoft SQL Server 2017 (v14.0.17224.0) and Management Studio.

Current table:

```
+-----------+----------+------------------+------------------+---------+------------+
|    vID    |   fID    |      RESULT      |     Recorded     | LineNBR | MeasureDSC |
+-----------+----------+------------------+------------------+---------+------------+
| 292837518 | 75174227 | 2018-01-01 12:53 | 2018-01-01 9:48  |       1 | First      |
| 292837518 | 75174227 | 2018-01-01 12:54 | 2018-01-01 9:48  |       1 | Next       |
| 295376471 | 76107803 | 2018-01-01 22:51 | 2018-01-01 23:03 |       1 | First      |
| 295376471 | 76107803 | 2018-01-01 22:51 | 2018-01-01 23:03 |       1 | Next       |
| 301032810 | 78252847 | 2018-01-01 13:24 | 2018-01-01 13:45 |       1 | First      |
| 301032810 | 78252847 | NULL             | 2018-01-01 13:45 |       1 | Next       |
| 301867286 | 78566265 | 2018-01-01 14:40 | 2018-01-01 15:00 |       1 | First      |
| 301867286 | 78566265 | 2018-01-01 14:50 | 2018-01-01 15:00 |       1 | Next       |
| 302791918 | 78917501 | 2018-01-01 15:01 | 2018-01-01 7:30  |       1 | First      |
| 302791918 | 78917501 | 2018-01-01 15:05 | 2018-01-01 7:30  |       1 | Next       |
| 304444538 | 79538091 | 2018-01-01 8:00  | 2018-01-01 8:00  |       1 | First      |
| 304444538 | 79538091 | 2018-01-01 8:04  | 2018-01-01 8:00  |       1 | Next       |
| 304478684 | 79550758 | 2018-01-01 14:30 | 2018-01-01 17:44 |       1 | First      |
| 304478684 | 79550758 | 2018-01-01 15:30 | 2018-01-01 17:44 |       1 | Next       |
+-----------+----------+------------------+------------------+---------+------------+

```

The expecting output should be like this:

```
+-----------+----------+------------------+------------------+------------------+
|    vID    |   fID    |     Recorded     |      First       |       Next       |
+-----------+----------+------------------+------------------+------------------+
| 292837518 | 75174227 | 2018-01-01 9:48  | 2018-01-01 12:53 | 2018-01-01 12:54 |
| 295376471 | 76107803 | 2018-01-01 23:03 | 2018-01-01 22:51 | 2018-01-01 22:51 |
| 301032810 | 78252847 | 2018-01-01 13:45 | 2018-01-01 13:24 | NULL             |
| 301867286 | 78566265 | 2018-01-01 15:00 | 2018-01-01 14:40 | 2018-01-01 14:50 |
| 302791918 | 78917501 | 2018-01-01 7:30  | 2018-01-01 15:01 | 2018-01-01 15:05 |
| 304444538 | 79538091 | 2018-01-01 8:00  | 2018-01-01 8:00  | 2018-01-01 8:04  |
| 304478684 | 79550758 | 2018-01-01 17:44 | 2018-01-01 14:30 | 2018-01-01 15:30 |
+-----------+----------+------------------+------------------+------------------+

```

I was trying to use PIVOT function but getting an error message all the time: "Invalid column name 'RESULT'." 

My code: 

```
SELECT 
    vID, fID,
    RESULT,
    Recorded,
    [First] AS [First],
    [Next] AS [Next]
FROM 
    (SELECT 
         vID, fID, RESULT, Recorded, MeasureDSC
     FROM 
         #temp) x
PIVOT 
    (MAX(RESULT) FOR MeasureDSC IN ([First], [Next])) p

```

Would appreciate any help!