custom sql server YTD function

  • Hello,

    I am looking to write a custom sql server 2005 function that

    does the year to date trick for me.

    my (simplified) tables look like this:

    --------current------------

    CarPeriodCostForMonth

    BMW10935

    Honda20910

    BMW10915

    --------planned------------

    CarmonthCostForMonth

    BMW10935

    BMW1095

    Honda20810

    BMW10955

    Does any of you have attempted that before and might give

    me some advice?

    a group by where month = 'P109' gives me the 109's which then have

    to be added to the P209's. writing tons of group by's becomes a mess thats why I am looking at a function.

    thanks

  • What does the data in the month column represent? Does 109 mean January 2009? If it does then I would write something like this:

    Select

    Car,

    Right(month, 2) as year,

    Sum(CostForMonth) as ytd_cost

    From

    current

    Group By

    Car,

    Right(month, 2)

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

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