KOvitt
asked on
Get last available day of year, from daily data group by year
Hello,
I have a bunch of daily data going back to 1993. I need to pull specific data from the last available day for each year (not always YYYY-12-31) and group by year.
Any tips on how I can achieve this? I know I can use MAX to get the latest day but I don't now how to do that for each individual year in one table.
Thanks!
I have a bunch of daily data going back to 1993. I need to pull specific data from the last available day for each year (not always YYYY-12-31) and group by year.
Any tips on how I can achieve this? I know I can use MAX to get the latest day but I don't now how to do that for each individual year in one table.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Haha wow, I apologize for wasting your time. I for some reason thought that wouldn't work and didn't bother to try. Thank you!
No problem at all. Glad I could help.
SET @PROC_YEAR = 1993
WHILE @PROC_YEAR < 2012
BEGIN
SELECT @PROC_YEAR AS THE_YEAR, MAX(MY_DATE)AS TE_DATE FROM MY_TABLE WHERE YEAR(MY_DATE) = @PROC_YEAR
SET @PROC_YEAR = @PROC_YEAR + 1
END