The following image is a part of Microsoft SQL Server 2008 R2 System Views. From the image we can see that the relationship between sys.partitions and sys
sys.partitions
sys
Try this:
...JOIN sys.allocation_units a ON (a.type=2 AND a.container_id = p.partition_id) OR (a.type IN (1, 3) AND a.container_id = p.hobt_id)