How can I write a query in SQL Server that returns a column for each variable of each unique ID? Below is a simplified example of what I am trying to accomplish. Would you be able to point me in the right direction?
Table_Exists
ID | LOCATION | STATUS
__________________________________
001 | top | 3
001 | mid | 1
001 | bot | 4
002 | top | 2
002 | mid | 2
002 | bot | 1
003 | top | 1
003 | mid | 4
003 | bot | 2
Here is a simplified example of what I am trying, obviously without success. The code below returns an error message for incorrect syntax around '=':
SELECT
ID,
LOCATION = top AS Top,
LOCATION = mid AS Middle,
LOCATION = bot AS Bottom
FROM
Table_Exists
I trying to build:
Table_Desired
ID | Top | Middle | Bottom
__________________________
001| 3 | 1 | 4
002| 4 | 2 | 2
003| 1 | 4 | 2