SOLVED!Sometimes just revisiting your problem brings the answer! Here's what I came up with:SELECT DISTINCT a.id AS UserID, COALESCE((SELECT MIN(code) FROM @LOG b WHERE a.id = b.id AND [Month] = 1),0) AS Jan, COALESCE((SELECT MIN(code) FROM @LOG b WHERE a.id = b.id AND [Month] = 2),0) AS Feb, COALESCE((SELECT MIN(code) FROM @LOG b WHERE a.id = b.id AND [Month] = 3),0) AS Mar, COALESCE((SELECT MIN(code) FROM @LOG b WHERE a.id = b.id AND [Month] = 3),0) AS AprFROM @LOG a
COALESCE(value,0) converts the NULLs to Zero, and MIN(code) protects me from accidental duplicate entries and gives priority to the lower numbered codes. Plus this executes very quickly. Comments/Tweaks are still welcome.