Michael writes "I am really stumped here and I hope someone can help.I need to find all occurances of 3 consecutive negative values in a data set. So if the reading is consistantly negative for 3 days, I want the data from the 3rd day. (location, product, date)The following example shows 5 days of values, and 2 occurances of 3 day negative values.M -1T -5W -3 <--gimmeTh -9 <--gimmeF +2So I need the following returned (wednesday and thursdays data);LOCATION PROD READDATE ----------- ----- ----------- 1 1 03/16/2005 1 1 03/17/2005
Here is some sample data;DECLARE @myTable table (Location int,Prod int,ReadDate smalldatetime,Value int )insert into @myTable values(3,1,'12/11/2004',-29)insert into @myTable values(3,1,'12/12/2003',163)insert into @myTable values(3,1,'12/13/2003',-603)insert into @myTable values(3,1,'12/14/2003',-553)insert into @myTable values(3,1,'12/15/2003',-73)insert into @myTable values(3,1,'12/16/2003',-476)insert into @myTable values(3,2,'12/11/2003',-39)insert into @myTable values(3,2,'12/12/2003',76)insert into @myTable values(3,2,'12/13/2003',98)insert into @myTable values(3,2,'12/14/2003',-4)insert into @myTable values(3,2,'12/15/2003',-515)insert into @myTable values(3,2,'12/16/2003',-23)insert into @myTable values(6,1,'12/11/2003',904)insert into @myTable values(6,1,'12/12/2003',-621)insert into @myTable values(6,1,'12/13/2003',-466)insert into @myTable values(6,1,'12/14/2003',-314)insert into @myTable values(6,1,'12/15/2003',338)insert into @myTable values(6,1,'12/16/2003',37)
Which should give me;LOCATION PROD READDATE ----------- ----- ----------- 3 1 12/15/2003 3 1 12/16/2003 3 2 12/16/2003 6 1 12/14/2003
Thanks in advance."