Here is my question for you.I have a table with 2 columns. One Column Contains TimeStamps and the other a counter. I need to find the TimeStamps, which has its counter greater than both the time stamp before it and after it.eg.12/Apr/2010 2:22:13 40012/Apr/2010 2:23:13 50012/Apr/2010 2:25:15 30012/Apr/2010 2:26:13 10012/Apr/2010 2:28:15 20012/Apr/2010 2:29:15 10012/Apr/2010 2:30:15 200
if the data is as above the non strike through records below are those, I need to get.12/Apr/2010 2:22:13 40012/Apr/2010 2:23:13 50012/Apr/2010 2:25:15 30012/Apr/2010 2:26:13 10012/Apr/2010 2:28:15 20012/Apr/2010 2:29:15 10012/Apr/2010 2:30:15 200
ie. The time before 12/Apr/2010 2:23:13, the count is less than 500 and the time after 12/Apr/2010 2:23:13, the count is less than 500.And it is same in case of 12/Apr/2010 2:28:15 For any other set of 3 consecutive timestamps, the middle one has a value higher than both sides.Here is the code to generate some random data. Declare @T DateTime, @Val int, @i int, @Val1 intCreate table #hc (dt datetime, hits int)-- Drop table #hcSet @i = 0Set @T = convert(varchar(17),getdate()) While @i < 100Begin Set @T = DATEADD(minute,1,@T) Set @Val = 1000 * rand() Set @Val1 = 100 * rand() if @Val/100 <> @Val1/10 -- (this is done to get some 1 minute difference skipped) Begin insert into #hc Select @T, @Val; Set @i = @i + 1 EndEnd-- here is the data containg table Select convert(varchar(17),dt) as dt, hits from #hc
ThanksSrinika