You want a cross tab query. Check this out: http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/
It explains how to do a simple cross tab query which may be all you need. However, it looks like you may also benefit from the stored procedure the writer created to overcome some shortcomings of the cross tab query.