• You can use ISNULL() on each column pivoted (ISNULL([Oranges], 0) as Oranges) or you could try a pre-aggregated Cross tab which might give you a performance boost.

    SELECT SalesPerson,

    SUM( CASE WHEN Product = 'Oranges' THEN SalesAmount ELSE 0 END) Oranges,

    SUM( CASE WHEN Product = 'Pickles' THEN SalesAmount ELSE 0 END) Pickles,

    SUM( CASE WHEN Product = 'Bananas' THEN SalesAmount ELSE 0 END) Bananas,

    SUM( CASE WHEN Product = 'Apples' THEN SalesAmount ELSE 0 END) Apples,

    SUM( CASE WHEN Product = 'Grapes' THEN SalesAmount ELSE 0 END) Grapes,

    SUM( CASE WHEN Product = 'Melons' THEN SalesAmount ELSE 0 END) Melons,

    SUM( CASE WHEN Product = 'Beans' THEN SalesAmount ELSE 0 END) Beans

    FROM (

    SELECT SalesPerson,

    Product,

    SUM( SalesAmount) SalesAmount

    FROM names

    GROUP BY SalesPerson,

    Product) t

    GROUP BY SalesPerson

    Reference: http://www.sqlservercentral.com/articles/T-SQL/63681/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2