none
Finding the last day of the year

    Question

  • I have a series of dates that constitute 5 years of financial data. I need to find the last day recorded for a year. Problem is the data is in trading days and doesn't always end on the 31st of december. Dates are in yyyy-mm-dd format using the date datatype. I can find the last day of an individual year using the MAX function no problem. The question is how can I find the last day for every year in my dataset WITHOUT using cursors?

    Tuesday, April 17, 2012 2:44 PM

Answers

  • SELECT DATEPART ( yyyy , datefield ) as DateYear, MAX(DateField)

    FROM TABLE

    GROUP BY DATEPART ( yyyy , datefield )


    Chuck

    • Marked as answer by falcon00 Wednesday, April 18, 2012 4:59 AM
    Tuesday, April 17, 2012 2:47 PM
  • select max(date)
    from table
    group by year(date)
    • Marked as answer by falcon00 Wednesday, April 18, 2012 4:59 AM
    Tuesday, April 17, 2012 2:47 PM

All replies