I have a live data stream on a 2 minutes interval, that I wish to analyze in (near) real time. A snippet of this data is shown here:
This data is getting stored in a SQL Server table.
Now, I am trying to code a stored procedure in SQL Server 2008 that fulfills this condition:
Highest - Max(Start,End) > Absolute Value(Start - End),
ITEM3
fulfills this condition.
Additionally, for ALL the items which fulfill the above condition, it should then go back in time and return the start of the first record which fulfills the condition of End (Value) > Start (Value)
So, in the case above, the value returned should be 209.1 & Item 3.
The condition is getting fulfilled for ITEM3 only in the above case @10:21 A.M.
Additional note: for the purpose of this query, the values of lowest are not being used.
Also, there are no Zero / Null values in this data stream (the .. is temporarily there).
With my limited knowledge on SQL subqueries etc, I am unable to get the desired result beyond the first condition.
select desc
from table1
where Highest - dbo.InlineMax(Start,End) > abs(Start- End)
InlineMax
is my UDF which returns the higher value.
TIA