• vilonel (4/8/2011)


    I have removed the "big spaces" and PF5 the sql qry but still get the Incorrect syntax near 'PIVOT' error - do you think it could be my SQL thats messing around or am I missing something in the below sql code - thanks

    DECLARE @demo

    TABLE (

    group_id INTEGER NOT NULL,

    value MONEY NOT NULL

    );

    INSERT @demo (group_id, value) VALUES (1, $1.00);

    INSERT @demo (group_id, value) VALUES (1, $2.00);

    INSERT @demo (group_id, value) VALUES (1, $3.00);

    INSERT @demo (group_id, value) VALUES (1, $4.00);

    INSERT @demo (group_id, value) VALUES (2, $5.00);

    INSERT @demo (group_id, value) VALUES (2, $4.00);

    INSERT @demo (group_id, value) VALUES (3, $3.00);

    INSERT @demo (group_id, value) VALUES (3, $2.00);

    INSERT @demo (group_id, value) VALUES (3, $7.00);

    INSERT @demo (group_id, value) VALUES (4, $2.00);

    SELECT group_id,

    value

    FROM @demo;

    SELECT P.[1], P.[2], P.[3], P.[4]

    FROM @demo D PIVOT(SUM(D.value) FOR D.group_id IN ([1], [2], [3], [4])) P;

    Which version of SQL Server are you using?

    --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)