Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Avg value between two weeks at the same hour

Author  Topic 

whiterabbot
Starting Member

18 Posts

Posted - 2008-12-04 : 19:01:09
I have measured data with ten minute intervals that have accumulated for the past 5 years. However, not all of the data is good and this data has been flagged. What I am trying to due is for every data measurements that have been flagged I want to average the data a week before and a week ahead for just that hour that the flagged data occurred.

Here is what I have so far,
SELECT (case when datepart(hh,ScaledData_801.TimeStamp)=datepart(hh,null_data2.TimeStamp) then ScaledData_801.CH1Avg else null END) as ws, datepart(hh,null_data2.TimeStamp)
FROM ScaledData_801, null_data2 where ScaledData_801.TimeStamp between dateadd(dd,-7,null_data2.TimeStamp) and dateadd(dd,7,null_data2.TimeStamp) order by ScaledData_801.TimeStamp,null_data2.TImeStamp

I have changed it a million times trying to average ScaledData_801.CH1Avg but it always times out. Any suggestion would be great!

Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-04 : 19:04:04
What happened to this one ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115645
Go to Top of Page

whiterabbot
Starting Member

18 Posts

Posted - 2008-12-04 : 19:13:17
I needed to change the syntax to get the desired results but it works a lot faster using between. I am using the null_data2.Timestamp is when all the bad data occurs.
Go to Top of Page
   

- Advertisement -