title: Sql Server 2008 Cross Tab Query
body: <p>I usually can figure out any sql queries I need for my applications, but I have recently been stumped by a Cross Tab query I need to create and was wondering if you could help?</p>
  
  <p>I have 3 tables</p>
  
  <pre><code>Category(catID, catTitle) 
  Equipment(equipID, make, model, quantity, catID, siteID)
  Site(siteID, title)
  </code></pre>
  
  <p>And I would like to create a Cross Tab query to display a result set like below</p>
  
  <pre><code>Category   Site1   Site2   Site3   Site4   Site5
  PC           2       0       10      3      6
  Camera       12      4       2       0      8
  Printer      3       2       1       1      2
  </code></pre>
  
  <p>The numbers displayed represent a total of each category item within each site using the quantity field withint the Equipment table. I have never had to do a Cross Tab query before and I am struggling to get this working.</p>