I have data structured as follows: column1 = datetime, column2=int
I am needing to take the max int from each hour and subtract the max int from the previous hour. i have already broken the datetime in to the datepart but am struggling to get the previous max. The problem is that there is not data for every hour but if the previous hour is null I am needing to go to the next previous hour until there is data. Any ideas of how to structure this?
You could select the date without the hour, the hour and the int which don't have nulls, sort it by date and hour into a a table with an identity field.
then join that table to itself via the identity field referencing the identity before it to get the previous max int, then you can subtract the two ints from each other.
If you post some example data, I can write a query for you. Pete