• CELKO (9/5/2012)


    I want to obtain an YTD value for every year and on the same row I have to put the ytd value of previous year .

    Your DDL is not a table because it has no key, your split the date into parts, we do not use FLOAT in SQL because of rounding errors and the laws concerning currency. Here is teh DDL for a valid table and your query.

    CREATE TABLE Foobar

    (cod CHAR(10) NOT NULL,

    foo_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,

    PRIMARY KEY (cod, foo_date),

    vague_value DECIMAL (12,5) NOT NULL);

    SELECT cod,

    SUM(vague_value)

    OVER (PARTITION BY cod

    ORDER BY foo_date ASC

    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

    AS vague_value_runtot

    FROM Foobar;

    Mr C this is a 2008 forum.........

    ==========================================================================================================================
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe