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. 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 ????
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 -
SELECT TagName,DateDiff(mm,Down,Up) as MinutesDown
-
FROM
-
( SELECT a.TagName,a.[Time] as Down,
-
(SELECT min([Time])
-
FROM TheTable b
-
WHERE b.[Value]='A_OK'
-
and b.TagName=a.TagName
-
and b.Time>a.Time
-
) as Up
-
FROM TheTable a
-
WHERE [Value]='ALARM'
-
)z
-
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!
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.
@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.
Delerna 1,134
Recognized Expert Top Contributor
oops my bad
Try this -
SELECT ID,TagName,Down,Up,DateDiff(mi,Down,Up) as MinutesDown
-
FROM
-
( SELECT a.ID,a.TagName,a.[Time] as Down,
-
(SELECT min([Time])
-
FROM MachineAlarm b
-
WHERE b.[Value]='A_OK'
-
and b.ID>a.ID
-
and b.TagName=a.TagName
-
and b.Time>=a.Time
-
) as Up
-
FROM MachineAlarm a
-
WHERE [Value]='ALARM'
-
)z
-
-
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
@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?
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.
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 -
SELECT ID, TagName, Down, Up, DateDiff('n',[Down],[Up]) AS MinutesDown
-
FROM (SELECT a.ID,a.TagName,a.[Time] as Down,
-
(SELECT min([Time])
-
FROM [MachineAlarm] b
-
WHERE b.[Value]='A_OK'
-
and b.ID>a.ID
-
and b.TagName=a.TagName
-
and b.Time>=a.Time
-
) as Up
-
FROM MachineAlarm a
-
WHERE [Value]='ALARM'
-
) z
-
This worked on my machine on your data in access 2003
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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!
|
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.
|
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:
|
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"
| |
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
|
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...
|
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...
|
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:
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |