title: Use SQL To Retrieve Row-wise Data As Columns
body: <p>I have a data set in a Sybase database that is modelled by the following <a href="http://sqlfiddle.com/#!3/ffe26/1" rel="nofollow"><strong>SQL Fiddle</strong></a></p>
  
  <p>Using the following basic query I can extract the subsequent data:</p>
  
  <p><strong>Query:</strong></p>
  
  <pre><code>SELECT [Scancode], [Product Name], [Store Name], [Quantity]
  FROM Sales
  JOIN Items
  ON   Items.PK  = Sales.ITM_FK
  JOIN Stores
  ON   Stores.PK = Sales.STO_FK
  </code></pre>
  
  <p><strong>Data:</strong></p>
  
  <pre><code>SCANCODE    PRODUCT NAME    STORE NAME  QUANTITY
  123456789   Milk            Tokyo       19
  123456789   Milk            New York    28
  123456789   Milk            London      37
  987654321   Eggs            Tokyo       46
  987654321   Eggs            New York    55
  987654321   Eggs            London      64
  192837465   Bread           Tokyo       73
  192837465   Bread           New York    82
  192837465   Bread           London      91
  </code></pre>
  
  <p>I would like to retrieve the data in an "item centric" format:</p>
  
  <pre><code>SCANCODE    PRODUCT NAME    Tokyo Sales  New York Sales  London Sales
  123456789   Milk            19           28              37
  987654321   Eggs            46           55              64
  192837465   Bread           73           82              91
  </code></pre>
  
  <p><em><strong>Is there a scalable &amp; efficient way to retrieve data in this format?</em></strong></p>
  
  <p>~ Scalable means that more stores can be added without modifying the query.</p>