473,655 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the production downtime I need from "ALARM Database"?

13 New Member
Database is simliar to this:
ID TIME TAGNAME VALUE
5967383 8/1/2008 1:00:24 AM I16MUDL11 ALARM
5967384 8/1/2008 1:00:24 AM I16MUDL09 ALARM
5967391 8/1/2008 1:00:32 AM I16MUDL11 A_OK
5967392 8/1/2008 1:00:32 AM I16MUDL09 A_OK
5967398 8/1/2008 1:00:36 AM I16MUDL11 ALARM
5967406 8/1/2008 1:01:10 AM I16MUDL11 A_OK
5967407 8/1/2008 1:01:10 AM I16MUDL09 A_OK



Description:
If the value equals "ALARM", the machine will break down until the corresponding "A_OK" appears. Each ALARM and A_OK have a "TAGNAME" that indicates different parts of the machine.

Goal:

We want to find out how much time we lose in producition due to the breakdown of different parts. So we need to calculate the time between each "ALARM" and "A_OK" for each different "TAGNAME".

Misc.
The database is huge, containing about 600,000 entries.

I need:
TagName Frequency Total Downtime


It's driving me crazy. Please please give me a helping hand.
Attached Images
File Type: jpg database question.JPG (34.0 KB, 268 views)
Dec 18 '08 #1
8 2660
Delerna
1,134 Recognized Expert Top Contributor
Working out a possible query.
What is the criteria for frequency>
Per day?
Per Week?
Per Month??
Per Year??
other ????
Dec 18 '08 #2
Delerna
1,134 Recognized Expert Top Contributor
This is straight out of my head and without data I can't test it.
Something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT TagName,DateDiff(mm,Down,Up) as MinutesDown
  2. FROM
  3. (  SELECT a.TagName,a.[Time] as Down,
  4.              (SELECT min([Time])
  5.               FROM TheTable b
  6.               WHERE b.[Value]='A_OK' 
  7.                  and b.TagName=a.TagName
  8.                  and b.Time>a.Time
  9.               ) as Up
  10.    FROM TheTable a
  11.    WHERE [Value]='ALARM'
  12. )z
  13.  
If that runs slow you could try
1) Adding an index to TheTable for TagName and Time together
2) Run the query each night as a DTS into a table and build your reports from that.

Good luck
I'm here for any questions!
Dec 18 '08 #3
superleochen
13 New Member
Thank you, Delerna.

I am trying your query. Hope it works.

Actually I shouldn't say "Frequency" , what I want is simply the total times each machine part, which is "Tagname", breakdown.
Dec 19 '08 #4
superleochen
13 New Member
@Delerna
Sorry, I can't get it work. I attach part of the record and hope you could play it around and continue to help me out.

Thanks.
Attached Files
File Type: txt machine alarm.txt (22.0 KB, 424 views)
Dec 19 '08 #5
Delerna
1,134 Recognized Expert Top Contributor
oops my bad

Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT ID,TagName,Down,Up,DateDiff(mi,Down,Up) as MinutesDown
  2. FROM 
  3. (  SELECT a.ID,a.TagName,a.[Time] as Down, 
  4.              (SELECT min([Time]) 
  5.               FROM MachineAlarm b 
  6.               WHERE b.[Value]='A_OK'  
  7.                  and b.ID>a.ID
  8.                  and b.TagName=a.TagName 
  9.                  and b.Time>=a.Time 
  10.               ) as Up
  11.    FROM MachineAlarm a 
  12.    WHERE [Value]='ALARM' 
  13. )z 
  14.  
  15.  
I added some extra conditions to the where clause of the subquery

and b.Time>=a.Time because a tagname can go down and back up in less than one second

and b.ID>a.ID because a taganame can go down and back up again multiple times in the same second.

Also the datediff parameter for minutes is mi not mm.
mm is months
Dec 21 '08 #6
superleochen
13 New Member
@Delerna
I try your updated code again and receive this error.

I think your algorithm is very good and in the right way. But it just didn't work in my computer. I am using Access 2003. Does that make any difference?
Attached Images
File Type: jpg error.JPG (14.4 KB, 158 views)
Dec 22 '08 #7
Delerna
1,134 Recognized Expert Top Contributor
Yes it might, I have given you SQLServer2000 code because you have posted into the SQL Server thread.

Having said that the syntax for SQL in SQLSever and Access are very similar and I know the query I have given you works in SQLServer because I have tested it on your sample data.

Let me fire up access and see what I can come up with.
Dec 22 '08 #8
Delerna
1,134 Recognized Expert Top Contributor
OK
In Access DateDiff uses n for minutes and it has to be in quotes
Also, try putting your table name in square brackets instead of quotes

Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, TagName, Down, Up, DateDiff('n',[Down],[Up]) AS MinutesDown
  2. FROM (SELECT a.ID,a.TagName,a.[Time] as Down,  
  3.              (SELECT min([Time])  
  4.               FROM [MachineAlarm] b  
  5.               WHERE b.[Value]='A_OK'   
  6.                  and b.ID>a.ID 
  7.                  and b.TagName=a.TagName  
  8.                  and b.Time>=a.Time  
  9.               ) as Up 
  10.    FROM MachineAlarm a  
  11.    WHERE [Value]='ALARM'  
  12. ) z
  13.  
This worked on my machine on your data in access 2003
Dec 22 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8682
by: Robin Tucker | last post by:
I have some code that dynamically creates a database (name is @FullName) and then creates a table within that database. Is it possible to wrap these things into a transaction such that if any one of the following fails, the database "creation" is rolledback. Otherwise, I would try deleting on error detection, but it could get messy. IF @Error = 0 BEGIN SET @ExecString = 'CREATE DATABASE ' + @FullName EXEC sp_executesql @ExecString
11
3649
by: RWC | last post by:
Hello, I'm having trouble converting code in Access XP / 2002. I have some code that declares an variable "as database" in Access 97, which is not recognized in Access XP. I've tried to find a refrence to the items that have changed between 97 and XP, and haven't been able to find anything yet. I will continue looking, but if anyone can shed some light on this fairly quickly, I would appreciate it. Thanks In Advance!
4
2309
by: (Pete Cresswell) | last post by:
I would argue that it is not. JET is a desktop DB engine. Sybase is a database Oracle is a database DB2 is a database. VB 6 is a front-end development tool. PowerBuilder is a front-end development tool. MS Access is a front end devlopment tool.
0
2270
by: Tom Wild | last post by:
Hi I am trying to connect to an Access database from a WebPage in VB.Net but when I try to open the connection I get the following error: The Microsoft Jet database engine cannot open the file 'C:\Test03\Test03.mdb'. It is already opened exclusively by another user, or you need permission to view its data My connection string is as follows:
1
3478
by: Tom Wild | last post by:
Hi I am trying to create a webform that connects to an Access database. If I use the connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gizmo\Gizmo.mdb" Then the application connects to the database and downloads data fine but when I try to fire an Update command I get the following error: "Problem firing System.Data.OleDb.OleDbCommand - Operation must use an updateable query"
7
3881
by: Risen | last post by:
Hi,all, I want to execute SQL command " DROP DATABASE mydb" and "Restore DATABASE ....." in vb.net 2003. But it always shows error. If any body can tell me how to execute sql command as above? Thanks a lot. Best regard. Risen
33
3310
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. The problem may come in using a renumber function which should take the steps in their current order...
2
2363
by: elgin | last post by:
I have a split Access 2003 database. I have signed the database with a Code Signing Certificate from Small Business Server. This works fine and users can have Access macro security on high or medium and do not get prompted at startup. The problem comes because there are two of us modifying the code. Whenever either one of us changes the code, one of us must resign both the front and back end of the database. If we forget to sign both, we...
24
1932
by: superleochen | last post by:
Database is simliar to this: ID TIME TAGNAME VALUE 5967383 8/1/2008 1:00:24 AM I16MUDL11 ALARM 5967384 8/1/2008 1:00:24 AM I16MUDL09 ALARM 5967391 8/1/2008 1:00:32 AM I16MUDL11 A_OK 5967392 8/1/2008 1:00:32 AM I16MUDL09 A_OK 5967398 8/1/2008 1:00:36 AM I16MUDL11 ALARM 5967406 8/1/2008 1:01:10 AM I16MUDL11 A_OK 5967407 8/1/2008 1:01:10 AM I16MUDL09 A_OK Description:
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.