1

In the data below Event1 represents the end of a manufacturing cycle. Event2 happens during on a percentage of the cycles. I was wondering if it is possible to pull the end of cycle time (when Event1 returns to 0) and the maximum value of Event2 (either 0 or 1) during that cycle. Both values are binary.

    DateTime          Event1        Event2
    12/5/2012 07:00      1             0
    12/5/2012 07:01      0             0
    12/5/2012 07:45      1             0
    12/5/2012 07:46      0             0
    12/5/2012 07:50      0             1
    12/5/2012 07:54      0             0
    12/5/2012 08:30      1             0
    12/5/2012 08:31      0             0


    DateTime          max(Event2)
    12/5/2012 07:46      0
    12/5/2012 08:31      1

I'm using WonderWare historian database, so there are some unique options in the query. Below is what I use to find the end of cycle times.

SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime
FROM WideHistory
WHERE wwRetrievalMode = 'Delta'
AND Event1 = 1
AND wwEdgeDetection = 'TRAILING'
AND wwVersion = 'Latest'
AND DateTime >= '20121205 07:00'
AND DateTime <= '20121205 09:00'")

Is there a way to use the results of this query to generate DateTime restrictions of additional queries?

2 Answers2

0

In a standard SQL database, I would characterize the periods by the end (when event1 happens) rather than the beginning of the period. The data contains the end, but not the beginning.

select EndOfCycleDateTime, count(*) as NumEvents,
       max(Event2) as maxEvent2
from (select t.*,
             (select min(datetime) from t t2 where t2.datetime >= t.datetime and t2.event1 = 1
             ) as EndOfCycleDateTime
      from t
     ) t
group by EndOfCycleDateTime

This is using a subquery to find the next time when event1 is 1. This should be the same value for everything in the cycle. The outer query just groups by this value.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Wonderware uses SQL server standard edition (plus some fancy extra stuff on the historian) by default, so you should be able to use T-SQL to get what you want.

http://wonderwarenorth.com.s138768.gridserver.com/support/TechTip_1004_WonderwareHistorian&DifferentRetrievalMethods.pdf

Taraz
  • 1,242
  • 13
  • 13