Re: pivot table without aggregation?



Something like this should do it:

SELECT SUM(CASE WHEN [Name] = 'Product A' THEN RankID ELSE 0 END) AS
'Product A',
SUM(CASE WHEN [Name] = 'Product B' THEN RankID ELSE 0 END) AS
'Product B',
SUM(CASE WHEN [Name] = 'Product C' THEN RankID ELSE 0 END) AS
'Product C'
FROM PRODUCTS

Note that since your product name is unique the SUM here is just to pull the
data into one row. You could use MAX too but then if there is negative rank
you may have to handle it differently.

If this list of products is very dynamic, then you should look into dynamic
pivoting. Here are a few resources if you want to look in that direction:
http://www.sqlmag.com/articles/index.cfm?articleid=15608
http://www.sqlmag.com/articles/index.cfm?articleid=94268
http://www.sqlteam.com/item.asp?ItemID=2955

Also, most reporting tools have very good support for pivoting.

HTH,

Plamen Ratchev
http://www.SQLStudio.com


.



Relevant Pages

  • Re: Problem with formula/doesnt pull data with slash (/)
    ... exactly what is in that cell. ... Do you actual want to SUM these numbers or return them as a string? ... but it doesnt pull the information i want in column ...
    (microsoft.public.excel.misc)
  • Sum Formula
    ... In column B I have Heading Year 2003 with data for each month. ... In column E I would like Sum for Last 12 months. ... So cell E2 would be Sum+Sum ... But this needs adjustment if I wish to pull in down the full column E. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Sum Formula
    ... Copy E2 down to E12 ... Rgds ... > In column E I would like Sum for Last 12 months. ... > But this needs adjustment if I wish to pull in down the full column E. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Sum Formula
    ... > Copy E2 down to E12 ... >> In column E I would like Sum for Last 12 months. ... >> But this needs adjustment if I wish to pull in down the full column E. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Formula Help
    ... I have a report, from which i need to pull the number of orders from any ... I need to calculate the sum of all orders for a particular month. ... Their are 166 orders for October (The data source lists the past ...
    (microsoft.public.excel.misc)