I'm considering buying Rock Band The Beatles for my only gaming console, the Nintendo Wii, but I was wondering if there are any big differences between the version on Wii and the version on Playstation 3?


Question: SQL Server. Join/Pivot/Performance help please
Answer: Use:

  SELECT p.instrumentsettingsid,
         i.status,
         SUM(CASE WHEN p.producttypeid = 1 THEN 1 ELSE 0 END) as 'Cash',
         SUM(CASE WHEN p.producttypeid = 2 THEN 1 ELSE 0 END) as HighInterest,
         SUM(CASE WHEN p.producttypeid = 3 THEN 1 ELSE 0 END) as 'ML Loan',
         SUM(CASE WHEN p.producttypeid = 4 THEN 1 ELSE 0 END) as 'Investment Note',
         SUM(CASE WHEN p.producttypeid = 5 THEN 1 ELSE 0 END) as 'Trading',
         SUM(CASE WHEN p.producttypeid = 6 THEN 1 ELSE 0 END) as 'DD Trading',
         SUM(CASE WHEN p.producttypeid = 7 THEN 1 ELSE 0 END) as 'ML Trading',
         SUM(CASE WHEN p.producttypeid = 8 THEN 1 ELSE 0 END) as 'NMLTrading',
         SUM(CASE WHEN p.producttypeid = 9 THEN 1 ELSE 0 END) as 'Individual Custody',
         SUM(CASE WHEN p.producttypeid = 10 THEN 1 ELSE 0 END) as 'ML Individual Custody',
         SUM(CASE WHEN p.producttypeid = 11 THEN 1 ELSE 0 END) as 'Custody',
         SUM(CASE WHEN p.producttypeid = 12 THEN 1 ELSE 0 END) as 'ML Custody Trading',
         SUM(CASE WHEN p.producttypeid = 13 THEN 1 ELSE 0 END) as 'Portfolio',
         SUM(CASE WHEN p.producttypeid = 14 THEN 1 ELSE 0 END) as 'ML Personal Portfolio',
         SUM(CASE WHEN p.producttypeid = 15 THEN 1 ELSE 0 END) as Other,
    FROM res_db..instrumentproducttypepermissions p
    JOIN res_db..instrumentsettings i ON i.id = p.instrumentsettingsid
   WHERE p.enabled = 1
     AND p.producttypeid BETWEEN 1 AND 15
GROUP BY p.instrumentsettingsid, i.status


No need for the LEFT JOIN...


  Also those 15 account names are hardcoded, in a perfect world it would get the product name from the table producttypes


Dynamic columns requires dynamic SQL.