Time to Pivot in 2k5

  • I can not get past the syntax on this query.  I am trying to use the new pivot command. Please help

    WITH

    ProductSales(Item, Customer, Sales)

    AS

    (

    SELECT

    [Item] + '(' +[Item_Key]+')' as Item ,[Customer_Name]+'('+[Customer_Code]+')' as Customer, [Sales_Fact_Quantity]

    FROM

    Brand_Dimension

    INNER JOIN Tbl_Item ON [Item_No] = [Item_Key]

    INNER JOIN Tbl_Consolidated_Sales_Fact ON [Sales_Fact_Item_No] = [Item_Key]

    INNER JOIN Tbl_Customer ON [Customer_Code] = [Sales_Fact_Sell_Customer]

    WHERE

    [Sales_Fact_DateTime] >= GETDATE()-91 AND [Product_Item_Active] = 1

    )

    SELECT

    Item, Customer

    FROM

    ProductSales

    PIVOT

    (

    SUM(Sales)

    )

    AS ProductSalesPivot

    ORDER

    BY

    ProductSalesPivot

    .Item

  • Also this is the error

    Msg 156, Level 15, State 1, Line 1

    Incorrect syntax near the keyword 'WITH'.

    Msg 170, Level 15, State 1, Line 22

    Line 22: Incorrect syntax near '('.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply