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.
| Author |
Topic |
|
pequeajim
Starting Member
3 Posts |
Posted - 2010-02-23 : 11:51:50
|
| I am looking for some suggestions; hopefully I can explain my situation clearly.We are currently capturing machine downtime in an external Historian and I have created a linked server to this Historical DB with SQL so that I can generate reports using reporting services.For a given machine center on each machine, we are tracking the status, (1- running, 0= down), along with the time of the event.I would like to report on the number of times down in a given time period, total time they were down, and time between failures.Time down starts when the bit goes to 0 and stops when it goes to 1. Time between failures starts when the bit goes to 1 and stops when it returns to zero.The user would select a manufacturing line and then time period.I am struggling in how to capture the slices of the events; any thoughts? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
pequeajim
Starting Member
3 Posts |
Posted - 2010-02-23 : 14:49:04
|
| I'm thinking of doing this with a couple of table value functions that move the raw data into a usable table that I can easily report against?One TVF would provide the extracted data for Mean Time Between Failure, (1=Run, then first 0=Down), and the second would give me the extracted data for Mean Time To Recover, (0=Down, then 1=Run)The report would kick off the procedure which would include running a cursor function that extract out the data so it can be reported on.I may not be using the right terminology for everything, but think the concept should be solid. I need to go back and study up on how to use this functionality in SQL Server. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-24 : 09:47:08
|
quote: Originally posted by pequeajim I'm thinking of doing this with a couple of table value functions that move the raw data into a usable table that I can easily report against?One TVF would provide the extracted data for Mean Time Between Failure, (1=Run, then first 0=Down), and the second would give me the extracted data for Mean Time To Recover, (0=Down, then 1=Run)The report would kick off the procedure which would include running a cursor function that extract out the data so it can be reported on.I may not be using the right terminology for everything, but think the concept should be solid. I need to go back and study up on how to use this functionality in SQL Server.
I assume you've fields like machinecenter,machine, status,date fields in your tablethen you could use the belowSELECT t.machinecenter,t.machine,SUM(CASE WHEN t.status=0 and t1.status=1 THEN 1 ELSE 0 END) AS downcount,SUM(CASE WHEN t.status=0 and t1.status=1 THEN DATEDIFF(ss,t.date,t1.date) ELSE 0 END) AS totaldowntime,SUM(CASE WHEN t.status=1 and t1.status=0 THEN DATEDIFF(ss,t.date,t1.date) ELSE 0 END) AS totaltimeavailableFROM YourTable t CROSS APPLY (SELECT TOP 1 date FROM YourTable WHERE machinecenter=t.machinecenter AND machine= t.machine AND status <> t.status AND date > t.date ORDER BY date ASC)t1GROUP BY t.machinecenter,t.machine ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|