What I'm trying to do is provide a value if another value doesn't exists within my pivot table.
Pivot table
SELECT *
FROM MyTable
PIVOT ( MAX(Number) for Total in ([Bob], [Jim], [Carol], [Simon])) as MaxValue
Result
Item | Bob | Jim | Carol | Simon
Item1 3 4 7
Item2 2 9 1
Item3 5
What I'm trying to improve on the table above is to show if the person has been assigned an item if there is no number there.
Expected result
Item | Bob | Jim | Carol | Simon
Item1 3 4 X 7
Item2 2 9 1 X
Item3 X X X 5
I have a column (was commented out above) that has the person's name if the person was assigned that item but I was thinking maybe I could use COALESCE
to place the "X" there if the user was assigned the item but nothing if not. Although I'm not able to find out how to do this. Perhaps this is the wrong approach. Let me know if I let out some information. Thanks!