views:

20

answers:

1

My example is similar to this - The only problem is I cannot rewrite this query to cope with columns that have spaces inside it

In the example below suppose that rather then [Oranges] you had ['Oranges And Apples'] in one cell.

For some reason adding an "'" means the pivot function returns NULL everywhere and [Oranges And Apples] is of course not valid

What am I doing thats wrong here?

http://www.mssqltips.com/tip.asp?tip=1019

SELECT SalesPerson, [Oranges] AS Oranges, [Pickles] AS Pickles
FROM
(SELECT SalesPerson, Product, SalesAmount
FROM ProductSales ) ps
PIVOT
(
SUM (SalesAmount)
FOR Product IN
( [Oranges], [Pickles])
) AS pvt
+1  A: 

You don't need the apostrophes.

( [Oranges and Apples], [Pickles])
Rob Farley