Pivot

  • Hi all,

    A quick question and silly one. Does Pivot in tsql work in ssms 2008 r2 ?

    i'm trying to use it but its throwing a syntax error. Below is the sample table and code that i borrowed from a website. I havent used pivot before.

    USE [Test]

    GO

    CREATE TABLE [dbo].[SoftwareDemo](

    [SoftwareName] [nvarchar](50) NOT NULL,

    [Count] [int] NOT NULL,

    [Country] [nvarchar](50) NOT NULL

    ) ON [PRIMARY]

    --insert the sample data:

    INSERT INTO SoftwareDemo VALUES ('Project', 15, 'Canada')

    INSERT INTO SoftwareDemo VALUES ('Visio', 12, 'Canada')

    INSERT INTO SoftwareDemo VALUES ('Project', 10, 'USA')

    INSERT INTO SoftwareDemo VALUES ('Visio', 5, 'USA')

    --Here’s our PIVOT query:

    SELECT Softwarename, Canada, USA, Canada + USA AS TOTAL FROM SoftwareDemo

    PIVOT

    (

    SUM([Count])

    FOR Country

    IN (Canada, USA)

    ) AS x

    --The error im gettin is:

    Msg 170, Level 15, State 1, Line 4

    Line 4: Incorrect syntax near '('.

  • Never mind....i got it.....i was on 2000 server...thanks all

  • kevin4u06 (12/28/2010)


    Never mind....i got it.....i was on 2000 server...thanks all

    Heh... scary stuff that we've all done. Glad it wasn't something like dropping a table from a dev server... or was that the production server? 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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